package com.javaninja.stringexamples;
public class StringExample2 {
//Difference between String "equals method" and "== operator"
public static void main (String args[])
{
String str1 = "Java";
String str2 = "Java";
System.out.println("Is str1==str2 ? " +( str1==str2)); //Prints true
System.out.println("Is str1 equals str2 ? " +( str1.equals(str2))); //Prints true
String str3 = new String("Java");
System.out.println();
System.out.println("Is str1==str3 ? " +( str1==str3)); //Prints false
System.out.println("Is str1 equals str3 ? " +( str1.equals(str3))); //Prints true
}
}
No comments:
Post a Comment