As simple as:
import java.util.stream.*;
public class MyClass {
public static void main(String args[]) {
Long x = Stream.of(1, 2, 3).map(i -> {
System.out.println(i);
return i + 4;
}).count();
System.out.println(x); // prints '3'
}
}
The count()
here is used in order to trigger the intermediate operations which include System.out.println(i)
, but nothing gets printed from inside map()
. Why is that?