This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
It is true. "abc" is a string because it is in double quotes. There are two such string objects one on the left hand side and another one on the right hand side. When this expression is evaluated, JVM tries to create two strings. Because the strings are identical, JVM reuses the string "abc" already created in the string pool instead of creating a duplicate one( very important concept ). So the reference of the string on the left hand side is the same as the reference of the string on the right hand side. Hence == returns true. Is it clear? Ajith
[This message has been edited by Ajith Kallambella (edited July 14, 2000).]
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Joined: Nov 22, 2008
True. String literals are stored in a string pool. Since String objects are immutable, this optimzation mechanism is safe to do. So, "abc" and "abc" can reference the same "abc" in the pool. But, beware of this: String s1 = new String("abc"); String s2 = "abc"; s1 == s2 is false because s1 is explicitly created on the heap.