Back to Intellij Community

FoldExpressionIntoStream

java/java-impl/resources/inspectionDescriptions/FoldExpressionIntoStream.html

2025.3-rc-2786 B
Original Source

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

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);
  }

New in 2018.2