Which class in java.lang provides a mutable sequence of characters without synchronization?

The story behind the answer

The java.lang class that provides a mutable, unsynchronized character sequence is StringBuilder.

Unlike String, whose contents cannot change after construction, StringBuilder modifies an internal character sequence through operations such as append, insert, delete, and replace. This makes it useful when code repeatedly constructs or edits text, such as while assembling a large message inside a loop. Converting the finished builder with toString() produces an immutable String.

StringBuilder is designed for ordinary single-threaded use and makes no guarantee of synchronization. Its API is closely compatible with StringBuffer, but StringBuffer synchronizes its methods for thread-safe use and may carry extra overhead. If multiple threads share and mutate the same text buffer, external coordination or an appropriate concurrent design is required.

StringBuilder implements CharSequence, not CharacterSequence—the latter is not the Java interface name. CharSequence is the abstraction also implemented by String and StringBuffer. The builder grows as needed, but its capacity can be set or expanded explicitly when the approximate output size is known, reducing reallocations during construction.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: