Java / Strings
What is the difference between creating String object using new and String literals?
When a String object is created using String literals, JVM searches at the String pool to find if any other String object is stored already with the same value. If found, it returns the reference to that String object from String pool otherwise it creates a new String object with given value and stores it in the String pool.
When we use new operator, JVM creates the new String object but don’t store it into the String Pool or try to reuse the existing objects with same value.
More Related questions...
instanceofCloneable is checked? What is the default implementation of equals method in Object class.