The StringBuffer class since java 1.0 should be replaced with the newer StringBuilder class in java 1.5 if you don’t need any synchronization. What I learned in college about StringBuffer which probably is the same with StringBuilder is that it is a lot more efficient when concatenating Strings.
String temp = “yo”;
yo += ” yo”;
Now you would think it would just append the second ” yo” to the end of temp, but what happens is that a new string is created and then everything is copied into it. This gets messy if you put the yo += “yo”; in a loop.
For StringBuilder and StringBuffer, it will just append the ” yo” to the StringBuilder object in a faster and space efficient setting. If you hit the end of the size of the StringBuilder, it’ll just increase the size automatically.