Originally posted by manishkumarlal cs: whats the different between String s = "abc"; and String s = new String("abc");
String is a very special class in JAVA. String s=new String("abc"): jvm create a String Object contained "abc" then return a refrence pointed to s. SO s a refrence not a real object. String s = "abc": jvm first use String.equals to find whether there is a same object in "string pool". if it get it, it will return this refrence pointed to s.if not, it will create a object in "string pool" and return the refrence. so you can try a experiment like this; String s1 = new String("abc"); String s2 = new String("abc"); use "==" to see whether they are equal. and use "String.equal()" to see whether they are equal. hope it will help you!