Back to Intellij Community

Java8CollectionRemoveIf

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

2025.3-rc-2359 B
Original Source

Reports loops which can be collapsed into a single Collection.removeIf() call.

Example:

for (Iterator<String> it = collection.iterator(); it.hasNext(); ) {
    String aValue = it.next();
    if(shouldBeRemoved(aValue)) {
      it.remove();
    }
  }

After the quick-fix is applied:

collection.removeIf(aValue -> shouldBeRemoved(aValue));