Java 8 Streams peek api

前端 未结 4 1938
暖寄归人
暖寄归人 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:07

    The documentation for peek says

    Returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream. This is an intermediate operation.

    You therefore have to do something with the resulting stream for System.out.println to do anything.

提交回复
热议问题