Java 8 Streams peek api

前端 未结 4 1937
暖寄归人
暖寄归人 2020-12-05 04:49

I tried the following snippet of Java 8 code with peek.

List list = Arrays.asList(\"Bender\", \"Fry\", \"Leela\");
list.stream().p         


        
4条回答
  •  执笔经年
    2020-12-05 05:19

    Streams in Java-8 are lazy, in addition, say if there are two chained operations in stream one after the other, then the second operation begins as soon as first one finishes processing a unit of data element (given there is a terminal operation in the stream).

    This is the reason why you can see repeated name strings getting output.

提交回复
热议问题