|NO.Z.00016|——————————|BigDataEnd|——|Java&核心类库.V01|——|Java.v01|string类.v01|常量池|概念|

一、String类和常量池的概念
### --- String类的概念(重点)

~~~     ——>        java.lang.String类用于描述字符串,Java程序中所有的字符串字面值都可以使用该类的对象加以描述,
~~~     ——>        如:"abc"。
~~~     ——>        该类由final关键字修饰,表示该类不能被继承。
~~~     ——>        从jdk1.9开始该类的底层不使用char[]来存储数据,而是改成 byte[]加上编码标记,从而节约了一些空间。
~~~     ——>        该类描述的字符串内容是个常量不可更改,因此可以被共享使用。
~~~     ——>        如:
~~~     ——>            String str1 = “abc”; - 其中"abc"这个字符串是个常量不可改变。
~~~     ——>        str1 = “123”; - 将“123”字符串的地址赋值给变量str1。
~~~     ——>                      - 改变str1的指向并没有改变指向的内容
二、编程代码
package com.yanqi.task12;

public class StringPoolTest {

    public static void main(String[] args) {

        // 1.验证一下常量池的存在
        // 到目前为止,只有String这个特殊类除了new的方式外还可以直接字符串赋值(包装类除外)
        String str1 = "abc";
        String str2 = "abc";
        System.out.println(str1 == str2); // 比较地址  true
    }
}
三、编译打印
D:\JAVA\jdk-11.0.2\bin\java.exe "-javaagent:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\lib\idea_rt.jar=51428:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\bin" -Dfile.encoding=UTF-8 -classpath E:\NO.Z.10000——javaproject\NO.H.00001.javase\javase\out\production\javase com.yanqi.task12.StringPoolTest
true

Process finished with exit code 0

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(18)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示