Cannot convert IntStream to some Object Stream

前端 未结 2 1056
萌比男神i
萌比男神i 2021-01-01 10:35

I\'m trying to use an IntStream to instantiate a stream of objects:

Stream myObjects = 
       IntStream
        .range(0, count         


        
2条回答
  •  不知归路
    2021-01-01 11:20

    Stream stream2 = intStream.mapToObj( i -> new ClassName(i));
    

    This will convert the intstream to Stream of specified object type, mapToObj accepts a function.

    There is method intStream.boxed() to convert intStream directly to Stream

提交回复
热议问题