I have seen many questions regarding object created using string literal and new keyword like:
How many String objects using new operator
But it doesn't clarify my doubts.
Case 1: String object using string literal. It creates one object in string constant pool if,it is not present otherwise, return the reference of this object.This object is implicitly interned.
Case 2:String object using new(). it creates 2 objects,one in string constant pool and another one in heap area.Reference variable refer to the heap area object.For this object we need to call intern method to put this object into string constant pool explicitly.
My question is if new() already creates one object in string constant pool then, what is use of calling intern method on the object which is there in heap area?