Tutorials

Java String Methods


String contains() method


In java String contains( ) method checks if the required sequence of character is present in the input String or not.

If the character is present then the boolean value true is returned otherwise false is returned.

 

Example:


package string;

public class ContainsDemo {

      public static void main(String[] args) {

            String str = "Sun rises in the east";

            Boolean output1, output2;
         
            output1 = str.contains("rises in");
            System.out.println(output1);

            output2 = str.contains("west");
            System.out.println(output2);
      }

}


Please Share this page
Views : 102
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!