Re: difference between String s = "abc" and String s = new String("abc")
Tuesday, June 29, 2004 08:43 AM
String s = "abc" returns the reference of the value "abc" ( if exists) from the String pool from JVM. If there is no reference to "abc" in the String pool, it creates one. new of String() creates a new instance of String object.
Hence, if you compare the objects first-s and the second-s, they will be different. However first-s.equals( second-s ) will return true.