exampracticeonline.com
String contains()

Java String contains()

The java string contains() method is checked a sequence of characters are present in given string or not. It's return type is boolean value true or false. If sequence of characters are found in given string then it returns true otherwise it return false. 

We can say that, String.contains() to discover a substring is available in given string or not. Kindly remember that this method is case sensitive.

Method syntax

/**
* @param substring - substring to be searched in this string
*
* @return - true if substring is found,
*           false if substring is not found
*/
public boolean contains(CharSequence s) {
    return indexOf(s.toString()) > -1;
}

Method Signature

public boolean contains(CharSequence s)  

Method Parameter

s : specifies the sequence of characters(substring) to be searched.

Method Returns

In Java, String contains() method return type is boolean type. It's return value true or false.

if sequence of char value(substring) exists in given string then it should return true otherwise return false.

Method Exception

String.contains() method does not accept 'null' argument. If null string is searchig then It will throw NullPointerException in case method argument is null.

Exception in thread "main" java.lang.NullPointerException
    at java.lang.String.contains(String.java:2120)
    at com.StringContains.main(StringContains.java:11)