Inspectopedia Help

Expression can be folded into Stream chain

Reports expressions with a repeating pattern which could be replaced with Stream API or String.join().

Example:

boolean allStartWith(String a, String b, String c, String d, String prefix) { return a.startsWith(prefix) && b.startsWith(prefix) && c.startsWith(prefix) && d.startsWith(prefix); }

After the quick-fix is applied:

boolean foo(String a, String b, String c, String d, String prefix) { return Stream.of(a, b, c, d).allMatch(s -> s.startsWith(prefix)); }

Example:

String joinAll(String a, String b, String c, String d) { return a + "," + b + "," + c + "," + d; }

After the quick-fix is applied:

String joinAll(String a, String b, String c, String d) { return String.join(",", a, b, c, d); }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

FoldExpressionIntoStream
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Java language level migration aids | Java 8

This inspection depends on the Java feature 'Stream and Optional API' which is available since Java 8.

New in 2018.2

Availability

By default bundled with

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin

Java, 241.18072

Last modified: 18 June 2024