当前位置:网站首页>Common class String overview
Common class String overview
2022-08-10 05:54:00 【hagong9】
String

Strings are constants and cannot be changed after creation.
String literals are stored in the string pool and can be shared.
The case list is as follows.
1. String literals are stored in the string pool. The memory map is as follows.

2. Immutability: Change the value of name to "Zhang San", instead of directly changing "hello" to "Zhang San" in the memory, but to re-create "Zhang San" in the string pool,name changed from pointing to "hello" to pointing to "Zhang San"

3. Add a new variable name2, the value is "Zhang San", then name2 will go to the string pool to find out whether there is "Zhang San", and if so, assign "Zhang San" to name2, so thatConstant sharing is achieved.

Another way to create strings.
In this way, a "string Java" is created in the heap, and then see if there is "java" in the string pool, if not, create one.At this point the address of the variable str is the address of "Java" in the heap.


Think about it, if you use this method to create a str2 with the value "java", then str == str2?The answer is not the same, creating an object will open up a new space in the heap, and the address given to str2 is different from the address of str.


边栏推荐
- The Principle of Union Search and API Design
- IDEA的database使用教程(使用mysql数据库)
- Ten years of sharpening a sword!The digital collection market software, Link Reading APP is officially open for internal testing!
- 测一测异性的你长什么样?
- Common class BigDecimal
- 去中心化和p2p网络以及中心化为核心的传统通信
- 各个架构指令集对应的机型
- cesium listens to map zoom or zoom to control whether the content added on the map is displayed
- IO stream【】【】【】
- 一个基于.Net Core 开源的物联网基础平台
猜你喜欢

LeetCode 1720.解码异或后的数组(简单)

Link reading good article: What is the difference between hot encrypted storage and cold encrypted storage?

优先队列

Common class BigDecimal
![[List Exercise] Traverse the collection and sort by price from low to high,](/img/49/183ebabf99e31af0d095bfd05a0b1f.png)
[List Exercise] Traverse the collection and sort by price from low to high,

最新最全的数字藏品发售日历-07.27

LeetCode 162.寻找峰值(中等)

最新最全的数字藏品发售日历-07.26

【笔记】集合框架体系 Collection

pytorch-10.卷积神经网络(作业)
随机推荐
Operation table Function usage
One step ahead, don't miss it again, the chain reading APP will be launched soon!
网络安全作业
符号表
图片批量添加水印批量缩放图片到指定大小
sqlplus displays the previous command and the available backspace key
力扣——统计只差一个字符的子串数目
笔记1
分享一款恋爱星座男女配对微信小程序源码
学生管理系统以及其简单功能的实现
我不喜欢我的代码
多表查询 笔记
Bifrost micro synchronous database implementation services across the library data synchronization
事务、存储引擎
[Difference between el and template]
Batch add watermark to pictures batch add background zoom batch merge tool picUnionV4.0
LeetCode 面试题17.14 最小k个数(中等)
String常用方法
tinymce rich text editor
LeetCode 剑指offer 21.调整数组顺序使奇数位于偶数前面(简单)