当前位置:网站首页>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.
边栏推荐
- 栈和队列
- ORACLE系统表空间SYSTEM占满无法扩充表空间问题解决过程
- LeetCode 面试题17.14 最小k个数(中等)
- el-dropdown drop-down menu style modification, remove the small triangle
- 去中心化和p2p网络以及中心化为核心的传统通信
- Linux database Oracle client installation, used for shell scripts to connect to the database with sqlplus
- Copy large files with crontab
- 集合 Map
- Privatisation build personal network backup NextCloud
- 先人一步,不再错过,链读APP即将上线!
猜你喜欢
I use this recruit let the team to improve the development efficiency of 100%!
String常用方法
符号表
Chain Reading|The latest and most complete digital collection sales calendar-08.02
最新最全的数字藏品发售日历-07.26
链读推荐:从瓷砖到生成式 NFT
pytorch-10.卷积神经网络(作业)
[Notes] Collection Framework System Collection
链读好文:Jeff Garzik 推出 Web3 制作公司
Link reading good article: What is the difference between hot encrypted storage and cold encrypted storage?
随机推荐
Notes 1
A timeout error is reported when connecting to Nacos
菜谱小程序源码免费分享【推荐】
一个基于.Net Core跨平台小程序考试系统
21天挑战杯MySQL-Day05
各个架构指令集对应的机型
树结构——二叉查找树原理与实现
学生管理系统以及其简单功能的实现
去中心化和p2p网络以及中心化为核心的传统通信
network security firewall
LeetCode 面试题17.14 最小k个数(中等)
view【】【】【】【】
索引笔记【】【】
作业实验四
The Principle of Union Search and API Design
WeChat applet wx.writeBLECharacteristicValue Chinese character to buffer problem
MySql constraints
Likou - Number of Provinces
Small program wx.request simple Promise package
cesium listens to map zoom or zoom to control whether the content added on the map is displayed