Java StringBuilder class is an inbuilt class that is used to create a modifiable, i.e., mutable string (unlike the String class which provides immutable strings). The StringBuilder class is used to represent the collection/sequence of characters. The StringBuilder class is similar to the StringBuffer class, except that the StringBuilder class is non-synchronized and StringBuffer is synchronized. When there is only a single thread (i.e., the program is not multi-threaded), the StringBuilder class has an advantage over the StringBuffer class being faster than it.

StringBuilder Class in Java

The StringBuilder class is available since JDK 1.5. It can be imported from the java.lang package. Java StringBuilder class is also used to create the mutable (modifiable) string object.

StringBuilder class provides the API compatible with StringBuffer, but with no guarantee of synchronization. StringBuilder class is designed for use as a drop-in replacement for StringBuffer in places where the single thread was using the string buffer.

Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under the most implementations.

Instances of StringBuilder are not safe for use by the multiple  threads. If such synchronization is required, then it is recommended that StringBuffer be used.

#java #stringbuilder #java stringbuilder

StringBuilder Class in Java Example | Java StringBuilder Class
2.35 GEEK