I am new to JAVA programming. I have read it in my book
String a="Hello";
String b="Hello";
System.out.println(a==b);
This should return false as a & b refer to different instances of String objects.
Bcoz the assignments operator compares the instances of objects but Still I am getting a true.
I am using Eclipse IDE.
Example in book goes as this:
String s = "s";
String sToo = "s";
System.out.println(a == b);
System.out.println(s == sToo);
That bit of code prints “false” for s == sToo. That's because s and sToo are references to different instances of the String object. So, even though they have the same value, they are not equal in the eyes of the equality operators. Also, s == “s” prints false, because the string literal produces yet another instance of the String class.
Name of book: JAVA 7 for Absolute Beginners