Parameters s − This is the sequence to search in Java contains() method Return Value The contains() method in Java returns true only if this string contains “s” else false. Exception Java String contains() Method Example 1: Output: Contains sequence ‘ing’: true Contains sequence ‘Example’: true Contains sequence ‘example’: false Contains sequence ‘is String’: false
When to use Contains() method?
contains() in Java is a common case in programming when you want to check if specific String contains a particular substring. For example, If you want to test if the String “The big red fox” contains the substring “red.” The string contains() in Java method is useful in such situation. Java String contains() Method Example 2: Java String contains() method in the if else Structure: Output: The Keyword :example: is not found in the string class Java