Back to Intellij Community

IndexOfReplaceableByContains

java/java-impl/resources/inspectionDescriptions/IndexOfReplaceableByContains.html

2025.3-rc-2347 B
Original Source

Reports comparisons with String.indexOf() calls that can be replaced with a call to the String.contains() method.

Example:

boolean b = "abcd".indexOf('e') >= 0;

After the quick-fix is applied:

boolean b = "abcd".contains('e');

This inspection only reports if the language level of the project or module is 5 or higher.