I found a quiz about Java 8 Stream API of peek method as below
Arrays.asList("Fred", "Jim", "Sheila")
.stream()
.peek(System.out::println)
.allMatch(s -> s.startsWith("F"));
The output is
Fred
Jim
I am confused how this stream works? My expected result should be
Fred
Jim
Sheila
The peek() method is an intermediate operation and it processes each element in Stream. Can anyone explain me this.