当前位置:网站首页>String不同创建方式的区别
String不同创建方式的区别
2022-06-29 03:57:00 【梦中千秋】
例子
public static void main(String[] args) {
String str1 = "aaa";
String str2 = "aaa";
System.out.println(str1 == str2);
String str3 = new String("aaa");
String str4 = new String("aaa");
System.out.println(str3 == str4);
}
我们知道 == 比较引用类型是比较的引用地址,可以发现第一个输出true,第二个输出false,这是因为str1和str2都指向字符串常量池中的 “aaa” 的引用地址 , 而str3和str4 创建了一个新对象 ,“凡是new出来的都存在堆(Heap)内存中”,是在堆内存中的, 不一样的引用地址。
边栏推荐
- 分布式id解决方案
- The second meeting of the Second Council of Euler open source community was held, and Xinhua III, hyperfusion and Godson Zhongke became members of the Council
- 【新功能】Ambire 钱包集成了 Metis 网络
- On June 27, 2022, I have the right to choose the journey of the summer vacation.
- sql两列变为多行过滤显示
- leetcode - 295. 数据流的中位数
- MySQL review materials (additional) case when
- What is the dry goods microservice architecture? What are the advantages and disadvantages?
- Data collection and management [9]
- [World Ocean Day] tcapulusdb calls on you to protect marine biodiversity together
猜你喜欢

【C语言】解决 “address of stack memory associated with local variable ‘num‘ returned”

【新功能】Ambire 钱包集成了 Metis 网络

基于可变参模板实现的线程池

百度智能云服务网格产品CSM发布 | 火热公测中

MySQL复习资料(附加)case when

Why are you a test / development programmer? Can you recall

做 SQL 性能优化真是让人干瞪眼
![[Brillouin phenomenon] Study on simultaneous measurement system of Brillouin temperature and strain distribution in optical fiber](/img/92/57792ef733964230d36e0b9bb218b4.png)
[Brillouin phenomenon] Study on simultaneous measurement system of Brillouin temperature and strain distribution in optical fiber

Preliminary construction of SSM project environment

New listing of operation light 3.0 -- a sincere work of self subversion across the times
随机推荐
Preliminary construction of SSM project environment
leetcode - 295. Median data flow
[tcapulusdb knowledge base] Introduction to tcapulusdb restrictions
Data statistical analysis (SPSS) [6]
sink端 一般都是jdbc的insert update delete么?
Error: schema validation failed with the following error: the data path '' should not have other properties (projects)
Anaconda自带的Spyder编辑器启动报错问题
VG4131SxxxN0S1无线模块硬件规格书
How to back up all data on Apple mobile phone in 2 steps (free)
树莓派用VNC Viewer方式远程连接
[MCU framework][dfu] DFU upgrade example with CRC verification + timeout mechanism +led indicator + chip locking + chip self erasure
开发者方案 · 环境监测设备(小熊派物联网开发板)接入涂鸦IoT开发平台
Technology: how to design zkvm circuit
高性能限流器 Guava RateLimiter
做 SQL 性能优化真是让人干瞪眼
情绪的变化需要控制
Data collection and management [12]
中小型企业网络的组建
[interview guide] AI algorithm interview
自己动手搭建一个简单的网站