posted 17 years ago
When you create a string using new operator , it creates the string object for you in the heap.But when you create a string using a construct similar to below then it creates the string in the string pool and before creating it checks whether a equivalent object is already present there or not.If yes ; then it returns the reference back.
String s = "ab";
As strings are made immutable therefore multiple references to the same object can be returned safely.
You can see that the string class in final , so that none of its methods could be overriden.