How to fill the whole array with specific number using the arrays class in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        int[] arr = {1, 2, 3, 4};
        
        java.util.Arrays.fill(arr ,9);

        for (int n : arr) {
            System.out.println(n);
        }
    }
}



/*

run:

9
9
9
9

*/

 



answered Jul 21, 2019 by avibootz

Related questions

2 answers 211 views
2 answers 252 views
3 answers 270 views
3 answers 298 views
2 answers 298 views
...