30.4. Class StringBuilder

Once a String object is created, its contents can never change. We now discuss the features of class StringBuilder for creating and manipulating dynamic string information—that is, modifiable strings. Every StringBuilder is capable of storing a number of characters specified by its capacity. If the capacity of a StringBuilder is exceeded, the capacity is automatically expanded to accommodate the additional characters. Class StringBuilder is also used to implement operators + and += for String concatenation.

Performance Tip 30.2

Java can perform certain optimizations involving String objects (such as sharing one String ...

Get Java™ How to Program, Seventh Edition 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.