Connect Wen connection: StringTable
Test Case:
/**
* 演示字符串字面量也是【延迟】成为对象的
*/
public class TestString {
public static void main(String[] args) {
int x = args.length;
System.out.println(); // 字符串个数 2275
System.out.print("1");
System.out.print("2");
System.out.print("3");
System.out.print("4");
System.out.print("5");
System.out.print("6");
System.out.print("7");
System.out.print("8");
System.out.print("9");
System.out.print("0");
System.out.print("1"); // 字符串个数 2285
System.out.print("2");
System.out.print("3");
System.out.print("4");
System.out.print("5");
System.out.print("6");
System.out.print("7");
System.out.print("8");
System.out.print("9");
System.out.print("0");
System.out.print(x); // 字符串个数
}
}
How to test it, we use the Memory box under IDEA in debug mode detection
This Memory
is used to analyze the object jvm heap.
To quote the official introduction IDEA it.
The Memory view shows you the total number of objects in the heap:
When you step over the code, the Diff column shows how the number of objects changes between the debugger stops, which helps you see how the code you are stepping affects the heap.
Double-click a class name to view all instances of this class:
Run the program in Debug mode
2365 still can be found, the observation program, as has been the object of the runtime constant pool, naturally would not repeat created.