Inspectopedia 2025.2 Help

Call to 'set.removeAll(list)' may work slowly

Reports calls to java.util.Set.removeAll() with a java.util.List argument.

Such a call can be slow when the size of the argument is greater than or equal to the size of the set, and the set is a subclass of java.util.AbstractSet. In this case, List.contains() is called for each element in the set, which will perform a linear search.

Example:

public void check(String... ss) { // possible O(n^2) complexity mySet.removeAll(List.of(ss)); }

After the quick fix is applied:

public void check(String... ss) { // O(n) complexity List.of(ss).forEach(mySet::remove); }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

SlowAbstractSetRemoveAll
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Performance

New in 2020.3

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection SlowAbstractSetRemoveAll

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2025.2, Qodana for JVM 2025.2,

Last modified: 18 September 2025