The following is from http://www.jchq.net/essentials/d0e1214.htm: ---------------------------------------------------------------------- Note that if you construct two Strings with the same String literal, without using the new keyword, e.g. String a = "Hello" String b = "Hello" , then Java creates only one String object, so a==b evaluates as true. ------------------------------------------------------------------------ I think a==b should evaluate as false since they are pointing to two different String object.
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
String literals are stored in the String pool without duplicates so they do point to the same String. Compare this: String a = "JAVA"; String b = "JAVA"; System.out.println(a == b); to this: String a = new String("JAVA"); String b = new String("JAVA"); System.out.println(a == b);