Java examples for Collection Framework:Array Fill
fill a generic array
public class Main{ public static <E> void fill(final E[] array, final ArrayFillFunction<? extends E> func) { for (int i = 0; i < array.length; ++i) { array[i] = func.getElementForIndex(i); }//from w w w .java 2s. c om } public static <E> void fill(final E[] array, final ArrayFillFunction<? extends E> func, final int from, final int to) { for (int i = from; i < to; ++i) { array[i] = func.getElementForIndex(i); } } }