Java 8 fill array with supplier

后端 未结 4 1735
执念已碎
执念已碎 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:26

    Alternative to Pshemo's solution you could use map method.

    Object[] array = new Object[size];
    array = Arrays.stream(array).map(a -> new Object()).toArray();
    

提交回复
热议问题