Inspectopedia Help

Call to 'list.containsAll(collection)' may have poor performance

Reports calls to containsAll() on java.util.List.

The time complexity of this method call is O(n·m), where n is the number of elements in the list on which the method is called, and m is the number of elements in the collection passed to the method as a parameter. When the list is large, this can be an expensive operation.

The quick-fix wraps the list in new java.util.HashSet<>() since the time required to create java.util.HashSet from java.util.List and execute containsAll() on java.util.HashSet is O(n+m).

Example:

public boolean check(List<String> list, Collection<String> collection) { // O(n·m) complexity return list.containsAll(collection); }

After the quick-fix is applied:

public boolean check(List<String> list, Collection<String> collection) { // O(n+m) complexity return new HashSet<>(list).containsAll(collection); }

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.

SlowListContainsAll
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 2022.1

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.2, Qodana for JVM 2024.2,

Can be installed with plugin:

Java, 242.22892

Last modified: 11 September 2024