functional programming - Java 8 fill array with supplier -


Is there a way to fill an array using Java 8?

I would like to write:

  Supplier & lt; Object & gt; Supplier = () - & gt; New object (); Object [] array = new object [size]; Arrays.fill (array, supplier);  

Note: I know that I can write my own method.

when you fill out an already existing ARA View data from the supplier, or use it with creative solution:

  arrays.asList (array) .replaceAll (x -> supplier.get ( )); // If you have no problem with   creating a new array  , then you use `subList`  

You can also overwrite a category. You can use

  object [] array = stream.generate (Supplier), filled with the results generated by the supplier .limit (arraySize) .toArray (); You can use  toArray (IntFunction & lt; YourType [] & gt; for different types of / /  objects  / ^^^^^^^  

will return the new array; generator); as toArray (YourType [] :: new) ().

  string [] array = stream.generate (Supplier). Limit (10) .toArray (String [] :: New;);  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -