0

As per the Java docs Specification-

When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(java.lang.Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.

Why doesn't the following code create a literal in Constant pool when interned?

String a = "abc"; String b = a.substring(1); b.intern();

enter image description here

Why shouldn't be "bc" added to the String Constant pool.

Arijit Dasgupta
  • 325
  • 3
  • 14

0 Answers0