public class Test{
public static void main(String[] args){
String s1 = "abc";
//从字符的index=1开始截取,存入s2中
String s2 = s1.substring(1);
//显示s2中内容 s2 = bc;
System.out.println(s2);
//将s2中内容替换
String s3 = s2.replace("bc","xyz");
//显示s3——s3 = xyz;
System.out.println(s3);
//新建字符串对象newS1 —— 创建两个对象一个存在于堆内存中;
String newS1 = new String("abc");;
// 操作符 == 比较的是地址值;其中s1存在于常量池,因此为flase
System.out.println(s1 == newS1);
//equals()方法比较的是两对象内容
System.out.println(s1.equals(newS1));
}
} |