Sponsered Links
Categories
Sponsered Links

Java string contains method example

 

This example illustrates Java string contains method example. In this example contains() method checks the sequence characters and number or both characters and numbers together passed in parentheses into the called String. The method ables to find the sequence of characters(sp) therefore it return true and the method also ables to find the symbol underscore(_) therefore it return true.


public class StringContains {
  public static void main(String args[]) {
   
    String str = "jsp servlet tutorial", str1 = "420_9211", str2, str3;

    CharSequence char0 = "sp", char1 = "_";
    boolean result = str.contains(char0);
  
    System.out.println("Method returns true here:  " "'" + result + "'");
    result = str1.contains(char1);
    System.out.println();
   
    System.out.println("Return True: " "'" + result + "'");

    System.out.println();
    str2 = " jsp tutorial, servlet tutorial, java tutorial";
    System.out.println("Return False: " "'"+ str2.contains("jsp servlet""'");

  }

}

 


 

 
 
Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved