Inspectopedia Help

'List.indexOf()' expression can be replaced with 'contains()'

Reports any List.indexOf() expressions that can be replaced with the List.contains() method.

Example:

boolean hasEmptyString(List<String> list) { // Warning: can be simplified return list.indexOf("") >= 0; }

The provided quick-fix replaces the indexOf call with the contains call:

boolean hasEmptyString(List<String> list) { // Quick-fix is applied return list.contains(""); }

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Java, 241.16690

Last modified: 29 April 2024