当前位置:网站首页>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" 相同的对象实例。
所以前者其实理解为被后者的所包含。
边栏推荐
- NLP-D58-nlp比赛D27&刷题D14&读论文&mathtype
- 数字物业管理成趋势,传统物业公司如何通过转型实现数字化蝶变?
- High imitation Betta app
- Idea automatically generates unit tests, doubling efficiency!
- Smart doc + Torna compatible version
- APP性能优化之启动流程分析
- Detailed explanation of index invalidation caused by MySQL
- 如何保证高速公路供电可靠
- 三款很酷很骚气的底部导航
- Docker Deployment redis
猜你喜欢

ACM. Hj89 24 point operation ●●●

Docker deploy redis
![Restore IP address [standard backtracking + standard pruning]](/img/e6/5f9d2a5af973b6c7051ed434a4b93d.png)
Restore IP address [standard backtracking + standard pruning]
![[proteus simulation] example of T6963C driving pg12864 (with Chinese and English display)](/img/e7/d36750c729b76f18418589356706f1.png)
[proteus simulation] example of T6963C driving pg12864 (with Chinese and English display)

Notepad++ practical function sharing (common methods for replacing the end and beginning of regular lines, text comparison function, etc.)

三款很酷很骚气的底部导航

How to take the PMP Exam agile on June 25? Share your troubles
![The input parameter is object, but it was passed as [object object] because it needs to be converted to JSON format](/img/8c/b1535e03900d71b075f73f80030064.png)
The input parameter is object, but it was passed as [object object] because it needs to be converted to JSON format

格林公式挖洞法中内曲线顺时针的直观解释

Loop caused by add of sublist in list
随机推荐
节流和防抖
Postman返回值中文乱码????
docker redis集群配置
How to take the PMP Exam agile on June 25? Share your troubles
GBASE观察:扩展分析型数据库
开口式霍尔电流传感器助力直流配电改造
7、STM32——LCD
mcu常用寄存器位操作方式汇总
AutoCAD -- summarize three methods of drawing rounded corners in CAD
【Bug】C# IQueryable里的元素更改不了值
NLP-D58-nlp比赛D27&刷题D14&读论文&mathtype
Big guy on security privacy computing escort data security needs to pay attention to science and technology ethics at the same time
MySQL导致索引失效的情况详解
UART协议时序总结
Grpc security -2: fast implementation of server-side JWT authentication
Gbase observation: extended analytical database
docker 部署redis
冶金行业数字化供应链管理系统:平台精益化企业管理,助力产业高质量发展
Golang type assertion
Facebook open source shimmer effect