Java Stream Debugging
This is my first article and I thought I'd share an IntelliJ feature, perhaps not so obvious: Debugging a Stream. I've asked around and very few developers have known what to do in front of something like this:
in.stream().map(String::toLowerCase).sorted(String::compareTo).toList();
Many devs propose as a solution to understand what happened something like:
for(String s: strings){
System.out.println("s = " + s);
}
Let's see how to do it!
In our dear IntelliJ IDE, we insert as breakpoint the line where our stream is
Now you will need to run the software in debug mode up to the breakpoint. In the Debug Perspective, select the "Trace Current Stream Chain" button
This will be the result
There is also the split mode which allows you to explore the stream point by point
NB: the first loading of this interface may take a few moments to load the stream!