StringBuilder Class

Package: java.lang

StringBuilder represents a mutable sequence of characters. That is, a string that can be changed. This sets it apart from the String class, which represents an immutable sequence of characters. StringBuilder can be more efficient than String in applications that do a lot of string maniuplations.

TechnicalStuff.eps The StringBuilder class has a nearly identical twin called the StringBuffer class. Both classes have the same methods and perform the same string manipulations. The only difference is that whereas the StringBuffer class is safe to use in applications that work with multiple threads, StringBuilder is not safe for threaded applications but is more efficient than StringBuffer. As a result, you should use the StringBuffer class instead of the StringBuilder class if your application uses threads.





Creates a new empty StringBuilder.

String(String str)

Creates a new StringBuilder object whose value is identical to str.





Appends the string representation of the primitive type to the end of the string.

append(Object obj)

Calls the object’s toString method and appends the result to the end of the string.

append(CharSequence seq)

Appends the string to the end of the StringBuilder’s string value. The parameter ...

Get Java For Dummies Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.