Home > Java > javaTutorial > body text

How to debug Java Stream operations in IntelliJ IDEA

WBOY
Release: 2023-05-09 11:25:07
forward
1534 people have browsed it

Stream operation is a highlight of Java 8! Although java.util.stream is very powerful, there are still many developers who rarely use it in actual work. One of the most complained reasons is that it is difficult to debug. This was indeed the case at the beginning, because stream is like this When the streaming operation is in DEBUG, it is just one line of code. When going directly to the next step, many operations are actually passed at once, so it is difficult for us to judge which line in it is the problem.

Plug-in: Java Stream Debugger

How to debug Java Stream operations in IntelliJ IDEA

#If the IDEA version you are using is relatively new, this plug-in already comes with it, so you don’t need to install it. . If it has not been installed yet, install it manually and continue with the following operations.

This article is included in the "Fun IDEA Column" that I am serializing. This series should be written in the form of e-books. If you want immersive reading and learning, you can visit the Web version: https://www .didispace.com/idea-tips/

How to debug Java Stream operations in IntelliJ IDEA

Debug Stream operation

Video demonstration: Click here to view

First look at the following This code:

public class StreamTest {
    @Test
    void test() {
        List<String> list = List.of("blog.didispace.com", "spring4all.com", "openwrite.cn", "www.didispace.com");

        List<String> result = list.stream()
                .filter(e -> e.contains("didispace.com"))
                .filter(e -> e.length() > 17)
                .toList();

        System.out.println(result);
    }
}
Copy after login

The logic of this code is to filter the elements in the list collection through stream. Since there are two filters, when a problem occurs, you may not know which filter it is from. problem.

With the help of the powerful IDEA, when we encounter a stream, we only need to click the button in the picture below:

How to debug Java Stream operations in IntelliJ IDEA

A Stream operation will pop up. The tracking window:

How to debug Java Stream operations in IntelliJ IDEA

The label in this window is each step of this stream operation. We can judge by clicking the label to view the results before and after each step is executed. Is the filter here executed correctly?

The above is the detailed content of How to debug Java Stream operations in IntelliJ IDEA. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template