Files
javaSE-0419/day08/src/com/inmind/string01/StringDemo01.java

27 lines
1.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind.string01;
/*
常用类_String的概述和特点
1.String类代表字符串。 Java程序中的所有字符串文字例如"abc" )都被实现为此类的实例。
""双引号字符串就是String类的对象所以就可以直接调用String类的方法
2.字符串不变; 它们的值在创建后不能被更改。 因为String对象是不可变的它们可以被共享。
*/
public class StringDemo01 {
public static void main(String[] args) {
//创建2个学生对象
Student s1 = new Student("小王", 18);
Student s2 = new Student("小王", 18);
System.out.println(s1);
System.out.println(s2);
System.out.println(s1 == s2);//false 注意:引用数据类型中保存的是地址,当前地址不同
//定义2个字符串对象
String str1 = "abc";//str1中保存是地址所有引用数据类型保存的永远是地址
System.out.println(str1);//这里由于String类的底层源码重写了toString方法所以打印的是对应地址指向的内容
String str2 = "abc";
System.out.println(str1 == str2);//true
}
}