'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 | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |
Last modified: 13 July 2023