当前位置:网站首页>String s = new String(“xyz“) 创建了几个字符串对象?
String s = new String(“xyz“) 创建了几个字符串对象?
2022-06-23 22:18:00 【王家五哥】
一个或两个。如果字符串常量池已经有“xyz”,则是一个;否则,两个。
当字符创常量池没有 “xyz”,此时会创建如下两个对象:
一个是字符串字面量 "xyz" 所对应的、驻留(intern)在一个全局共享的字符串常量池中的实例,此时该实例也是在堆中,字符串常量池只放引用。
另一个是通过 new String() 创建并初始化的,内容与"xyz"相同的实例,也是在堆中。
String s = "xyz" 和 String s = new String("xyz") 区别?
两个语句都会先去字符串常量池中检查是否已经存在 “xyz”,如果有则直接使用,如果没有则会在常量池中创建 “xyz” 对象。
另外,String s = new String("xyz") 还会通过 new String() 在堆里创建一个内容与 "xyz" 相同的对象实例。
所以前者其实理解为被后者的所包含。
边栏推荐
- Niuke.com: the double pointer problem of receiving rainwater
- The digital transformation index report 2021 released by Tencent Research Institute has accelerated the digital transformation and upgrading of mainland enterprises!
- Server2022 activation
- 【HackTheBox】Fawn
- ACM. HJ89 24点运算 ●●●
- 关于H5移动端用什么自动化测试
- Idea automatically generates unit tests, doubling efficiency!
- 入参参数为Object,但传递过去却成了[object object] 是因为需要转为JSON格式
- Generate all possible binary search trees
- Revit API:明细表 ViewSchedule
猜你喜欢

1. < tag dynamic programming and path combination problem > lt.62 Different paths + lt.63 Different paths II

High imitation Betta app

接私活必备的 6 个开源项目

6 大完整开源项目,一次学个够

高仿斗鱼 APP

不容错过 | 华为内部资料--成功的项目管理PPT(123页)

依赖倒置原则

2018/GAN:Self-Attention Generative Adversarial Networks自我注意生成对抗网络

VS QT VTK 左下角显示同步小坐标轴

What is the production process of enterprise website? How long does it take to design and build a website?
随机推荐
再来一个高仿开眼的短视频APP
微信录制视频转圈效果如何实现?
组合总数II[每个元素只能用一次 + 去重复解集]
2022 information security engineer examination knowledge point: access control
高仿斗鱼 APP
[things about gbase] gbase 8s high availability technology and case analysis (issue 02)
高仿書旗小說 Flutter 版,學起來
High imitation Betta app
Leetcode——链表笔试题
老龄化下背景下,综合能效管理平台为医院保驾护航
Notepad++实用功能分享(正则行尾行首替换常用方法、文本比对功能等)
Taylor formula and common expansion
接私活必备的 6 个开源项目
What is the production process of enterprise website? How long does it take to design and build a website?
MySQL导致索引失效的情况详解
Differences between broadcastreceiver and localbroadcastmanager
《德阳市餐饮服务业油烟污染防治管理办法(征求意见稿)》之创新油烟监管
A person even ran a Weibo app
1004. 最大连续1的个数 III ●●
网站ssl证书