Java String contains() Method

Java String contains()

The contains() method checks whether the substring occurs within a given string or not.


Java Compiler
public class myClass { public static void main(String[] args) { String str1 = "country"; String str2 = "try"; String str3 = "con"; System.out.println(str1.contains(str2)); System.out.println(str1.contains(str3)); } }


public boolean contains(str2)

Parameter Values

str2RequiredSpecifies the substring to search for.

Return Value

trueIf the specified substring occurs within the given string.
falseIf the specified substring does not occurs within the given string.
NullPointerExceptionIf the returned value is null.

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author