How to know if a given string is substring from another string in Java

There is a contains() method! It was introduced in Java 1.5. If you are using an earlier version, then it’s easy to replace it with this:

str.indexOf(substr) != -1

Leave a Comment