标签:
char[] c={‘a‘,‘b‘,‘c‘};
Strintg s=new String(c);
//最后输出的结果是abc
//通过构造方法产生字符串
String s1 = "abc";
String s2 = "abc";
System.out.println(s1 == s2);
System.out.println(s1.equals(s2));
String s1 = new String("abc");
String s1 = new String("abc");
String s2 = "abc";
System.out.println(s1 == s2);
System.out.println(s1.equals(s2));
String s1 = "a" + "b" + "c";
String s2 = "abc";
System.out.println(s1 == s2);
System.out.println(s1.equals(s2));
String s1 = "ab";
String s2 = "abc";
String s3 = s1 + "c";
System.out.println(s3 == s2);
System.out.println(s3.equals(s2));
StringBuilder
(或 StringBuffer
)类及其 append
方法实现的。所以在堆内存中有新建了字符缓冲区的对象,所以比较两者的地址值是肯定不同的。标签:
原文地址:http://www.cnblogs.com/didixyy/p/796f9bcfbf07fd13d6f6caec711dca3d.html