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
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
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework