How to implement a Java stream?

后端 未结 5 898
悲哀的现实
悲哀的现实 2020-12-01 06:34

I want to implement a Stream.

I don\'t want to just use implements Stream, because I would have to implement a ton of met

5条回答
  •  隐瞒了意图╮
    2020-12-01 07:06

    For the sake of completeness, as I did not find this directly among the answers here on SO: If you want to transform an existing Iterator into a Stream (e.g., because you want to generate elements successively), use this:

    StreamSupport.stream(
        Spliterators.spliterator(myIterator, /* initial size*/ 0L, Spliterator.NONNULL), 
        /* not parallel */ false);
    

    I found this a bit hard to find, as you need to know StreamSupport, Spliterators and Spliterator

提交回复
热议问题