Inspectopedia Help

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

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

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

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023