Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

Java String: contains() Method

public boolean contains(CharSequence s)

The contains() method returns true if and only if this string contains the specified sequence of char values.

Java Platform: Java SE 8

Syntax:

contains(CharSequence s)

Parameters:

Name Description Type
s the sequence to search for String

Return Value: true if this string contains the specified sequence of char values, false otherwise.

Return Value Type: boolean

Pictorial presentation of Java String contains() Method

Java String: contains() Method

Example: Java String contains() Method


public class Example {

public static void main(String[] args)
    {
        String str1 = "Java Exercises and SQL Exercises";
        String str2 = "and";
System.out.println();
System.out.println("Original String: " + str1);
System.out.println("Specified sequence of char values: " + str2);
System.out.println(str1.contains(str2));
System.out.println();
    }
}

Output:

Original String: Java Exercises and SQL Exercises      
Specified sequence of char values: and                 
true

Java Code Editor:

Previous:concat Method
Next:contentEquals Method