August 2004
Intermediate to advanced
480 pages
9h 41m
English
The StringBuffer class is useful for making strings that need to be concatenated, appended to, or otherwise tangled with more than two or three times. Because regular String objects are immutable, changing a String actually creates a whole new String, which is an expensive operation. To make String-changing more efficient, we use StringBuffer. If you've done any work in C#, you'll recognize this as System.Text.StringBuilder.
There are generally only two things you do with a StringBuffer: append text to it, and then, when you're all done appending, call the toString() method to use it as a String. Like so:
package net.javagarage.demo.String; public class StringBufferDemo { public static void main(String[] ...Read now
Unlock full access