String s = new String("crispy"); Q: How many objects are created? /***********************************/ String s = new Sring ("creme"); String w = "creme"; Q: How many objects are created? /***********************************/ StringBuffer s = new StringBuffer("CrispyCreme"); String s = "CrispyCreme"; Q: How many objects are created?
Two. A string literal object "crispy" created in the string pool and a String Object in regular memory containing the characters "crispy"
Two. A string literal "creme" created in the string pool. A String object in regular memory containing the characters "creme". 'w' will point to the existing string literal object which contains the same characters "creme"
Two. Same reason as above for "creme" Whenever you see a string literal ie a string of characters in double quotes; a String literal will be created in the pool if one doesn't already exist. The 'new' operator always creates a unique string object in regular memory. Hope that helps. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform