fill a generic array - Java Collection Framework

Java examples for Collection Framework:Array Fill

Description

fill a generic array

Demo Code



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);
        }
    }
}

Related Tutorials