public static void main(String[] args) {
String str1 = new String("abc");
String str2 = new String("abc");
System.out.println(str1.equals(str2));//比较的是字符窜的内容 true
System.out.println(str1 == str2); //比较的是字符窜的地址 false
String str3 = "abc";
String str4 = "abc";
System.out.println(str3.equals(str4));//比较的是字符窜的内容 true
System.out.println(str3 == str4); //true 常量池
String str5 = "a";
for (int i = 0; i < 10; i++) {
str5 += i;
}
System.out.println(str5); //创建11 个对象
String str6 = new String("a");
for (int i = 0; i < 10; i++) {
str6 += i;
}
System.out.println(str6); //创建12个对象
}
//字符窜两位的截取
public static void method1(String string){
String regex = "(.{2})";
string = string.replaceAll (regex, "$1,");
System.out.print (string);
}