Java String contains() Method

Java String Contains

With this method, we can know whether or not the specified string contains the given character sequence. This is like finding whether plain is present in ”complaint”, and we have a true output.

Well, let’s have a simple program for understanding the method and observing output –

public class StringMethods {
public static void main(String[] args) {
String exampleString = “complaint”;
System.out.println(exampleString.contains(“plain”));
}
}

So, just executing this example comes up with the true output. This is because the example string contains the given character sequence. Just keep in mind that this method is case-sensitive.

So, you can do something like converting both the string and the character sequence that you are going to check into some convenient case before you really invoke the method.