Sponsered Links
Categories
Sponsered Links

Java string equals method example

 

This example illustrates Java string equals method example. In this example both objects posses same value but the type of value is different. Here two types of objects compared one is Integer type and the other one is String type so the method returns false as values types didnot match. Next method returns true if and only if none of the Strings compared posses null value and also must that there value matches each other in sequence, cases and all aspects of equality including value types Method returns true here as both Strings str1 and str2 posses same values, both the String mentioned above don't have any value but still Strings are equal as both are null type objects compared" and finally  Method returns false because values of Strings did not match when their respective letters case are concerned.

public class StringEquals {
  public static void main(String args[]) {

    Integer in = new Integer(1234);
    String str = new String("1234");   
    
    System.out.println"value types don't matches: " + in.equals(str));
    
    String str1 = new String("jsp servlet tutorial jsp tutorial servlet tutorial");
    String str2 = str1.substring(0);
    String str3 = " ", str4 = " ";
    String str5 = "jsp", str6 = "servlet";
   
    System.out.println("Return True:  " + str1.equals(str2));
   
    System.out.println("Return True
Method:  " + str3.equals(str4));
   
    System.out.println("Return False:  " + str5.equals(str6));
            
  }
}

 

 

 
 

 
 
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