Is there a way to fill an array using java 8 Supplier ?
I would like to write:
Supplier
In java.util.Arrays there is
void Arrays.setAll(T[] array, IntFunction generator)
This doesn't take a supplier; instead it takes an IntFunction whose input argument is the array index being filled. If your objects aren't dependent upon the destination array index, you can disregard the parameter and call a supplier like this:
Arrays.setAll(array, i -> supplier.get());
There are overloads for arrays of primitives as well as arrays of reference type. There is also a corresponding family of methods parallelSetAll() that does the same thing, except in parallel. (It uses streams internally.)