Files
javaSE-0113/day08/src/com/inmind/string01/Demo01.java

26 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 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因为""是字符串常量,固定不变的值,它被保存在常量池中
}
}