About java’s String Constant Pool

  java, jvm

String constant pool

Literal quantity creation form, stringstr1 = “droid”; The JVM detects this literal quantity, and here we think that no object with droid content exists. If the JVM cannot find the existence of a string object with droid content through the st ring constant pool, it will create the string object, then place the reference of the newly created object into the string constant pool and return the reference to the variable str1

Intern is followed by constant pool

HotSpot VM in JDK7 does not put String constants in native memory, but puts interedstring = > Java heap and Symbols => native memory

About intern

Before JDK6, constant pools were part of the permanent zone, but after JDK7, they were moved to the heap for management. The string. int () method obtains a symbol reference in the constant pool, and if the constant string does not exist in the constant pool, the method adds the string to the constant pool. Although the return value of the String.intern method is always equal to the string constant, it does not mean that the inter return of the same string is the same at all times of the system. (Although it is the same in more than 95% of cases) . Because there is a possibility that after an intern, the string is recycled at a certain time and then an intern call is made, then strings with the same literal amount are added to the constant pool again, but the reference positions are different.

Problem

Is the String object referenced by new in the method still present after the method is executed?

docs