Inspectopedia Help

Loop can be replaced with 'Collection.removeIf()'

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


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

After the quick-fix is applied:

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

This inspection only reports if the language level of the project or module is 8 or higher.

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3


Java, 233.SNAPSHOT

Last modified: 13 July 2023