http://www.javaresearch.org/Article/showArticle.jsp?column=545&thread=752
?
?
String class supports static strings, StringBuffer supports modifiable strings
Mainly considering the difference between the program execution efficiency, it will focus on these two differences. Simply talk: If the character content is not frequent, you can use String, otherwise StringBuffer.
If your character should involve adding new elements, or remove the element, use StringBuffer well, String also has a similar method, but it is also converted to a SRingBuffer.
Stingbuffer can operate on STING such as: StringBuffer SB = "SB"; string s = "s"; sb = sb.append (s); resulting result as "SBS" and Sting type can not
String points to static memory zones StringBuffer points to dynamic memory area
Example. String teststr = "aaa"; // one memory area is equivalent to string teststr = new string ("aaa"); teststr = "bbb"; // quite with red assignment a piece of memory Teststr = new string ("bbb") Teststr = "aaa" "bbb"; // teststr = new string ("aaa") New String ("BBB");
StringBuffer testbuffer = new stringbuffer (). Append ("aaa"); when the addition is calculated, he does not need to reassign the memory. Just TestBuffer.Append ("bbb"); StringBuffer can be built?
StringBuffer [] B_STR = New StringBuffer [20]