day08-常用类_String的概述和特点

This commit is contained in:
2026-01-20 11:45:17 +08:00
parent b75c027607
commit c5cbb6e5e6
2 changed files with 65 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
package com.inmind.string01;
/*
常用类_String的概述和特点
1.String类代表字符串。 Java程序中的所有字符串文字例如"abc" )都被实现为此类的实例。
""双引号字符串就是String类的对象所以就可以直接调用String类的方法
2.字符串不变; 它们的值在创建后不能被更改。 因为String对象是不可变的它们可以被共享。
*/
public class Demo01 {
public static void main(String[] args) {
//创建一个学生
Student s1 = new Student();
Student s2 = new Student();
System.out.println(s1);//地址
System.out.println(s2);//地址
System.out.println(s1 == s2);//false
//定义一个String类的对象
String str = "abc";//str是基本数据类型还是引用数据类型str中保存的是什么
System.out.println(str);//str保存的是地址由于println的源码实现导致String类型直接获取了内容打印
String str1 = "abc";//str1保存的是地址
System.out.println(str == str1);//true因为""是字符串常量,固定不变的值,它被保存在常量池中
}
}