package zhengze;
/*如果需要对字符串进行频繁拼接的话,使用StringBuffer或者StringBuilder
StringBuffer:【字符串缓冲器】是线程安全的,效率低
StringBuilder:【字符串操作类】是线程不安全的,效率高
package zhengze;
public class StringTest08 {
public static void main(String[] args) {
String aString = "a";
String bString = "b";
String cString = "c";
String dString = aString + bString + cString;
StringBuffer buffer = new StringBuffer();
buffer.append("a");
buffer.append("b");
buffer.append("c");
System.out.println(buffer);
String s = "abc";
System.out.println(s == buffer.toString());
System.out.println(s.equals(buffer.toString()));
// 需要把他转成字符串再比较,否则s会跟这个对象的内存地址作equals比较
// 最后那个改成s.equals(buffer.toString)
// buffer.toString())不调用toString()equals比较的就是对象,所以不能漏掉
}
}
-----------------------打印结果-----------------------------
abc
false
true