I understanding the internal working of intern() in java. It will start referring to the string pool area object. But when we use inter() along with new, does it still create an object in heap and the reference is now pointing to pool object? Or is it that it wouldn't create any heap object at all?
String s1 = new String("hello").intern();
For example in the above line, when intern is used, is it creating only one object in the string pool and referring it? Or is it creating one object in heap and one object in pool and it starts referring to pool object, thereby leaving the object at heap for garbage collection?