美文网首页
字符串那些事

字符串那些事

作者: canezk | 来源:发表于2016-10-18 15:31 被阅读7次

常量池

1、java中直接使用双引号展示的字符串会在常量池中直接创建
2、string.intern会先尝试在常量池中查找对象,如果存在就返回该对象在常量池中
的地址找不到就会先放入到常量池再返回地址
3、java7及以上,常量池放到了heap存储当中

使用建议

1、stringbuilder vs +
一般情况下+的操作编译器会做优化,为stringbuilder操作
问题:
More importantly given we have only 3 properties it might not make a difference, 
but at what point do you switch from concat to builder?
答案:
At the point where you're concatenating in a loop - that's usually when the 
compiler can't substitute StringBuilder by itself.

相关文章

网友评论

      本文标题:字符串那些事

      本文链接:https://www.haomeiwen.com/subject/btltuttx.html