Java String contains() method Example

Java String contains() method Example

The Java.lang.String contains() method Returns true if and only if this string contains the specified sequence of char values.

method signature:

public boolean contains(CharSequence s)

Example


package com.practice;

public class StringcontainsDemo {
public static void main(String[] args) {
String string = "Welcome To Home";

System.out.println(string.contains("To"));
System.out.println(string.contains("Home"));
System.out.println(string.contains("To Home"));
}

}

output


true
true
true
-->