The creation of a string for Java to be put into a string pool for code testing.
Excellent articles for reference
Java face question Series (ii)--How many string objects have been created?
public string (string original) API
Public String intern () API
Release Notes
JDK 1.7.0_71
New String () and intern ()
Packagethe pool of com.nicchagil.commonstudy.No01String; Public classCall { Public Static voidMain (string[] args) {String a= "ABC"; String b= "ABC"; String C=NewString (a); String D= "AB" + "C"; String e= "ABC". Intern (); String F=NewString (a). Intern (); System.out.println ("A = = B:" + (A = =b)); System.out.println ("A = = C:" + (A = =c)); System.out.println ("A = = d:" + (A = =d)); System.out.println ("A = = e:" + (A = =e)); System.out.println ("A = = f:" + (A = =f)); }}
Log
Truefalse true True
Variable, constant string concatenation, do they put in string Pool?
Packagethe pool of com.nicchagil.commonstudy.No01String; Public classCall2 { Public Static voidMain (string[] args) {FinalString A = "123"; FinalString B = "456"; String C= "123456"; String a= "123"; String b= "456"; System.out.println ("c = = (A + B):" + (c = = (A + b)));//A, B is final typeSystem.out.println ("c = = (\" 123\ "+ \" 456\ "):" + (c = = ("123" + "456"));//"123", "456" is constantSystem.out.println ("c = = (A + B):" + (c = = (A + b)));//A, B is a variableSystem.out.println ("c = = (A + \" 456\ "):" + (c = = (A + "456")));//A is a variableSystem.out.println ("c = = (A + b). Intern ():" + (c = = (A + b). Intern ()));//using the Intern () method }}
Log
Truetrue falsefalse true
Attention
The results of this log print are the results of the JDK run above.
When Java Java creates a string, what happens in the string Pool?