intern JDK1.8 in the String class () method of learning

jdk1.8 string constant pool is located in the stack;

Also creates a String object within the heap and constant pool (provided that the object has not constant pool) at the time jdk1.8 using the following command, but is a pointer to the heap s.

String s = new String ( "HELLO ");
a method of determining whether or not there will be constant pool s, if present, returns a reference constant pool, do not change the point s; if present (present in the stack but s points object), is established to the heap object reference in the constant pool;

s.intern ();
a method in an object is created in the constant pool (note and on a comparative), of course, provided the subject has not the constant pool;

String s = "hello";
the following method does not create the constant pool "hello world" objects, only created in the heap, and stack and has a constant pool "hello" and "world" objects;

String s = new String ( "hello ") + new String ( "world");
a method only to create objects in the constant pool, the stack is not;

String s = "hello" + "world";
 

Published 323 original articles · won praise 114 · Views 150,000 +

Guess you like

Origin blog.csdn.net/ywl470812087/article/details/105353379