Java 8 fill array with supplier

后端 未结 4 1733
执念已碎
执念已碎 2021-01-17 07:53

Is there a way to fill an array using java 8 Supplier ?

I would like to write:

Supplier supplier = () -> new Object();
Object[] arr         


        
      
      
      
4条回答
  •  青春惊慌失措
    2021-01-17 08:29

    You could easily write your own:

    public static  void fillArray(T[] array, Supplier supplier) {
        for(int k = 0; k < array.length; k++)
            array[k] = supplier.get();
    }
    

提交回复
热议问题