Back to Intellij Community

Convert2streamapi

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

2025.3-rc-2573 B
Original Source

Reports loops which can be replaced with stream API calls using lambda expressions.

Such a replacement changes the style from imperative to more functional and makes the code more compact.

Example:

boolean check(List<String> data) {
    for (String e : data) {
      String trimmed = e.trim();
      if (!trimmed.startsWith("xyz")) {
        return false;
      }
    }
    return true;
  }

After the quick-fix is applied:

boolean check(List<String> data) {
    return data.stream().map(String::trim).allMatch(trimmed -> trimmed.startsWith("xyz"));
  }