Java String contains() Method
Find out if a string contains a sequence of characters:
String myStr = "Hello"; System.out.println(myStr.contains("Hel")); // true System.out.println(myStr.contains("e")); // true System.out.println(myStr.contains("Hi")); // false
Definition and Usage
The contains() method checks whether a string contains a sequence of characters.
Returns true if the characters exist and false if not.
Syntax
public boolean contains(CharSequence chars)
Parameter Values
The CharSequence interface is a readable sequence of char values, found in the java.lang package.
Technical Details
COLOR PICKER
Report Error
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
Thank You For Helping Us!
Your message has been sent to W3Schools.
Top Tutorials
Top References
Top Examples
Get Certified
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.