标签:ring tao 字符串 static als java 初始 nbsp rgs
今天发现一个好玩的东西
public static void main(String[] args)
{
String str1 = new StringBuilder("ja").append("va").toString();
System.out.println(str1.intern() == str1);//false
String str2 = new StringBuilder("in").append("t").toString();
System.out.println(str2.intern() == str2);//false
String str3 = new StringBuilder("in").append("tu").toString();
System.out.println(str3.intern() == str3);//true
String str4 = new StringBuilder("in").append("tu").toString();
System.out.println(str4.intern() == str4);//false
String str7 = new StringBuilder("tao").toString();
System.out.println(str7.intern() == str7);//false
String str5 = "caotao";
System.out.println(str5.intern() == str5);//true
String str6 = new String("xiao");
System.out.println(str6.intern() == str6);//false
}
我想应该是初始化时java把java这个字符串以及48个关键字都放在了字符串常量池中。。。
各位大佬,小弟猜的对不对?
标签:ring tao 字符串 static als java 初始 nbsp rgs
原文地址:https://www.cnblogs.com/caotao0918/p/10853274.html