1,String s = new String("abc")
上述的語句中是創建了2個對象,第一個對象是"abc"字符串存儲在常量池中,第二個對象在JAVA Heap中的 String 對象。
2,String#intern
- 如果常量池中存在當前字符串, 就會直接返回當前字符串. 如果常量池中沒有此字符串, 會將此字符串放入常量池中后, 再返回
- 如果存在堆中的對象,會直接保存對象的引用,而不會重新創建對象
相關文章:
http://tech.meituan.com/in_depth_understanding_string_intern.html
https://juejin.im/post/58e51175a0bb9f006904bd09#comment