How to fill part of 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, 5, 6, 7};
        
        java.util.Arrays.fill(arr, 1, 4, 9);

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



/*

run:

1
9
9
9
5
6
7

*/

 



answered Jul 22, 2019 by avibootz

Related questions

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