/ Java  

Use Intellij to visualize debugging Stream operation

Last time I talked about the stream API feature in Java 8. It is a very good new feature, but unlike previously looping code, single-step debugging does not work for stream API. Luckily, IntelliJ IDEA provides a tool for us to visualize the stream code.

Example code:

1
2
3
4
5
6
List<Integer> numbers2 = Arrays.asList(1, 2, 3, 4, 5, 6, 7);

numbers2.stream()
.map(x -> x * x)
.filter(x -> x % 3 == 0)
.forEach(System.out::println);

Add a break point at the last line of stream

Start debug, and find the button in debug interface

Wait for a few seconds, you can see the results of each step of the stream operation