public class InternString{
public static void main(String[] args){
String str1="fly";
String str2="weigth";
String str3="flyweigth";
String str4=null;
str4=str1+str2;
System.out.println(str3==str4);
str4=(str1+str2).intern;
System.out.println(str3==str4);
}
}
本文通过一个Java示例程序展示了字符串常量池的概念及其使用方式。代码中比较了直接创建字符串和通过intern方法获取字符串引用的区别,帮助理解字符串在内存中的存储机制。
1704

被折叠的 条评论
为什么被折叠?



