当前位置:网站首页>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.


边栏推荐
猜你喜欢

链读好文:Jeff Garzik 推出 Web3 制作公司

多表查询 笔记

【笔记】集合框架体系 Collection

transaction, storage engine

链读 | 最新最全的数字藏品发售日历-07.28
![[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,

Chain Reading Recommendation: From Tiles to Generative NFTs

Chain Reading | The latest and most complete digital collection calendar-07.28

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

LeetCode 1351.统计有序矩阵中的负数(简单)
随机推荐
Common class BigDecimal
定时器(setInterval)的开启与关闭
LeetCode 162.寻找峰值(中等)
Chained Picks: Starbucks looks at digital collectibles and better engages customers
转载fstream,ifstream的详细用法
深度学习TensorFlow入门环境配置
.Net Core导入千万级数据至Mysql
图片批量添加水印批量缩放图片到指定大小
堆的原理与实现以及排序
GUI_AWT
wiki confluence 安装
网络安全3
链读好文:热加密存储与冷加密存储有什么区别?
大端以及小端以及读寄存器习惯
Smart contracts and DAPP decentralized applications
error in ./node_modules/cesium/Source/ThirdParty/zip.js
redis常见的面试题
Analysis of the investment value of domestic digital collections
opencv
基于 .NET Core MVC 的权限管理系统