Java: Consumer interface in a stream doesn't work as expected [duplicate]
问题 This question already has answers here : Java 8 Streams peek api (4 answers) How to use Streams api peek() function and make it work? (2 answers) Closed 2 years ago . I've got 2 statements, I expected that they should "print" same result: Arrays.stream("abc".split("")).forEach(System.out::println);//first Arrays.stream("abc".split("")).peek(new Consumer<String>() {//second @Override public void accept(String s) { System.out.println(s);//breakpoint } }); In fact, the first statement will print