*The equals() method is actually meant to compare the content of two objects, and not their location in memory.
'==' operator is used to compare two objects (it will consider both content and location in memory)
public class DifferentEqual {
public static void main(String[] args) {
String obj1 = new String("ABC");
String obj2 = new String("ABC");
System.out.println("equals() Method->");
if (obj1.equals(obj2))
System.out.println("True");
else
System.out.println("False");
System.out.println();
System.out.println("equal to equal operator->");
if (obj1==obj2)
System.out.println("True");
else
System.out.println("False");
}
}
No comments:
Post a Comment