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

This commit is contained in:
xx
2026-09-22 10:47:17 +08:00
parent 45eef578c7
commit 32d5c327bd
2 changed files with 31 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
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);//com.inmind.string01.Student@3b07d329
System.out.println(s1 == s2);//false
System.out.println("-----------------------");
String str1 = "abc";//str1保存的是地址!!
String str2 = "abc";//str2保存的也是地址!!
System.out.println(str1);//abc,由于println打印方法调用的是string类的toString,虽然是地址,但是输出了内容
System.out.println(str1 == str2);//true
}
}
@@ -0,0 +1,9 @@
package com.inmind.string01;
public class Student {
String name;
int age;
public Student() {
}
}