Filling up an array

Since JDK1.2, the utility class Arrays in the java.util package provides useful
array manipulation methods such as fill, binary search and sort.

You can easily fill up an array with a for loop:

      int values[] = { 5, 74, 23, 99, 6, 0, -2, -60 };
      for (int i=0; i<values.length; i++)
         values[i] = 69;

You could also use the Arrays.fill method defined for arrays of type byte[], char[],
double[], float[], int[], long[], object[].


      Arrays.fill(values, 69);

It doesn’t work any faster than writing the for loop yourself, it does exactly
the same (contains a for loop), except that it does some range checking.
So, theoretically using Arrays.fill is slower, but your code looks a lot cleaner.
Range checking is necessary if you want to fill up only part of the array using
fill(array, fromvalue, tovalue, value).

      Arrays.fill(values, 1, 4, 69);  yields in the array { 5, 69, 69, 69, 6, 0, -2, -60 }