System.out.println(s == s1);
// String 类 equals 重写(比较的内容)
System.out.println(s.equals(s1));
// 字符串是常量,它们的值在创建之后不能更改
// 一旦修改字符串存储的数据 自动创建一个的对象内部存储是修改的数据
String s2 = "abc";//new String("abc")
System.out.println(s2);
// String 把equals() 同时hashCode() 重新 都是内容相关
s2+=“def”;//new String(“abcdef”) 重新new一个对象,把新的空间地址给s2
System.out.println(s2);
// String 不变性(改变后会创建新的对象)
// String 类,性能不高
// byte[] by = {97,98,99,100,101,102};
// String b = new String(by);
// System.out.println(b);
// String bs = new String(by,0,3);
// System.out.println(bs);
String s4 = "gsdvukj";
char i = s4.charAt(5);
System.out.println(i);
System.out.println(s4.compareTo("gsduvbdkj"));
// s4.compareTo(“iuafdk”); 大于1 小于-1 等于0
//拼接字符串
System.out.println(s4.concat(“abc”));
String s5 = "kwesjbdv";
boolean bool = s5.contains("jd");
System.out.println(bool);
System.out.println(s5.endsWith("bdv"));
System.out.println(s5.startsWith("kw"));
String s6 = "abcdefg";
// 把字符串转换为字节数
byte[] by = s6.getBytes();
for(int j = 0;j<by.length;j++){
System.out.println(by[j]);
}
String s7 = "gudsvjkbguie";
// 查找字符串中指定的字符串的开始位置(找不到 返回 -1)
// 返回找到的一个匹配到的位置
int index = s7.indexOf(“d”);
System.out.println(index);
//字符串常量池(起缓存的作用)
// 把abc存储到缓存
String s8 = “abc”;
// new 一个字符串 一定在堆区开辟空间存储的abc(同时也会向缓存中存储abc)
// s9 指向堆区中new 的空间
String s9 = new String(“abc”);
System.out.println(s8 == s9);
// s9.intern() 返回对于缓存中的abc的地址
System.out.println(s8==s9.intern());
// 字符串常量池