w3resource logo

Introduction to Java Programming

Java String: contains() Method

Secondary Nav

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)


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

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("Original String: " + str1);
System.out.println("Specified sequence of char values: " + str2);


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

Java Code Editor:

Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program