public class InternDemo {
public static void main(String[] args){
/*
jdk7版本之后 字符串常量池从Perm Space移到Java Heap
*/
//生成两个对象
String s1 = new String("aaa");
//直接使用双引号声明出来的String对象会直接存储在常量池
String s2 = "aaa";
//非双引号声明的string对象,可以使用intern方法,若字符串存在,使用查询的字符串,若不存在将当前字符串放入常量池
s1.intern();
//比较堆内存地址
System.out.println(s1.equals(s2));
//比较引用地址
System.out.println(s1 == s2);
//equals相等,hashcode一定相等
System.out.println(s1.hashCode() == s2.hashCode()); //生成两个对象
String s3 = new String("") + new String("");
String s4 = "";
s3.intern();
System.out.println(s3.equals(s4));
System.out.println(s3 == s4);
System.out.println(s3.hashCode() == s4.hashCode());
/*
true
false
true
*/
}
}

最新文章

  1. 阿里云CentOS7系列三 -- 配置防火墙
  2. 关于内存管理/set/get方法
  3. HDU4276 The Ghost Blows Light SPFA&&树dp
  4. jsp获取枚举的值
  5. linux添加用户
  6. 【百度地图API】北京周边7日游——图标按路线轨迹行动
  7. jQuery基础---Ajax进阶
  8. Java面向对象回顾(1)
  9. halcon c++ 异常处理
  10. Solr中的group与facet的区别
  11. paloalto防火墙内存使用率高
  12. pair在vector和map中的使用
  13. Nginx下配置网站ssl实现https访问
  14. 7种方法实现移动端Retina屏幕1px边框效果
  15. PythonStudy——数据类型转化 Data type conversion
  16. centos7系统下hostname解析
  17. vscode sync插件 在不同设备 同步的坑
  18. Android 微信支付资料收集
  19. HTML5、CSS3与响应式Web设计入门(2)
  20. nginx和php-fpm通信的两种方式 unix socket和TCP

热门文章

  1. 腾讯的产品思维 VS 阿里的终局思维
  2. maven 继承
  3. 页面间固定参数,通过cookie传值
  4. sqlServer 获取最新的一条数据
  5. sqlserver——cube:多维数据集
  6. DAC连接
  7. 【转载】Python中的垃圾回收机制
  8. vs2010 2013 2015 有用各种功能插件
  9. Python: 遍历
  10. 【夯实Ruby基础】Ruby快速入门