java String类
String是一个特殊的类,它一但赋值后无法改变,它维护的是一个常量池。我们创建了两个String类型的变量 a和b,a="1";b=a,那么对a的值进行修改,那么b的值也不会被改变。因为是只读的。一旦给String类型的变量重新赋值,其实就是新创建一个对象。
package frank; public class App { public static void main(String[] args) { /* String s = new String("a"); String s2 = s; s=s.concat(""); System.out.println(s); System.out.println(s2); System.out.println(s.equals(s2));//true*/ /* String a = "a1"; String b = a; a = "a2"; System.out.println(b);//a1 */ String a = "hello"; String b = "he"; String c = "llo"; String d = b + c; c = "a1"; System.out.println(a.equals(d));//true } }