How to check if a string contains the sequences of characters or not using java ?

Answer : java.lang.String.contains() method searches the sequence of characters…

How to check if a string contains the sequences of characters or not using java ?

Contain() Method

  • java.lang.String.contains() method searches the sequence of characters in the given string. If sequence of char values are found in this string then print Yes otherwise print No.

Sample Code in Java

[pastacode lang=”java” manual=”%2F%20Java%20program%20to%20demonstrate%20working%20%0A%2F%2F%20contains()%20method%20%0Apublic%20class%20Wikitechy%20%7B%0A%0A%20%20%20%20%2F%2F%20Driver%20code%20%0A%20%20%20%20public%20static%20void%20main(String%20args%5B%5D)%20%7B%0A%20%20%20%20%20%20%20%20String%20s1%20%3D%20%22Welcome%20to%20Wikitechy%22%3B%0A%20%20%20%20%20%20%20%20if%20(s1.contains(%22kite%22)%20%3D%3D%20true)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22Yes%22)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%2F%2F%20prints%20true%20%0A%20%20%20%20%20%20%20%20else%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22No%22)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D” message=”” highlight=”” provider=”manual”/]

Output

Yes
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like