StringBuffer class and StringBuilder class
The value of String is immutable, which results in each operation on String generating a new String object, which is not only inefficient but also wastes a lot of limited memory space. For strings whose values frequently change, the StringBuffer and StringBuilder classes should be used.
The functions of the StringBuffer and StringBuilder classes are basically similar. The main difference is that the methods of the StringBuffer class are multi-threaded and safe, while the StringBuilder class is not thread-safe. In comparison, the StringBuilder class is slightly faster.
example:
public class Demo{
public static void main(String [] args){
String s = "1234567";
StringBuffer buffer = new StringBuffer();
buffer.append("ABC");
buffer.append(s);
buffer.append("abc");
System.out.println(buffer.toString());
}
}
This article comes from the CSDN blog. Please indicate the source when reprinting: http://blog.csdn.net/zzqLivecn/archive/2009/12/18/5029605.aspx
-