Java Stream Debugging
An IntelliJ feature with example

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

Non è stato fornito nessun testo alternativo per questa immagine

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

Non è stato fornito nessun testo alternativo per questa immagine

This will be the result

Non è stato fornito nessun testo alternativo per questa immagine

There is also the split mode which allows you to explore the stream point by point

Non è stato fornito nessun testo alternativo per questa immagine

NB: the first loading of this interface may take a few moments to load the stream!

To view or add a comment, sign in

More articles by Roberto Z.

Explore content categories