Java Collection How to - Fill array values








Question

We would like to know how to fill array values.

Answer

import java.util.Arrays;
/*  w ww  .j  a v  a  2s .  co  m*/
public class Main {

  public static void main(String[] args) {
    int[] integer = new int[10];
    System.out.println(Arrays.toString(integer));
    Arrays.fill(integer, 1, 4, 5);
    System.out.println(Arrays.toString(integer));
  }
}

The code above generates the following result.