Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 10. Fundamental Classes > The StringBuilder and the StringBuffer Classe...

10.5. The StringBuilder and the StringBuffer Classes

Thread-Safety

The classes StringBuilder and StringBuffer implement mutable sequences of characters. Both classes support the same operations. However, the StringBuffer class is the thread-safe analog of the StringBuilder class. Certain operations on a string buffer are synchronized, so that when used by multiple threads, these operations are performed in an orderly way (see Section 13.5, p. 626). Note that a String object is also thread-safe—because it is immutable, a thread cannot change its state. String builders are preferred when heavy modification of character sequences is involved and synchronization of operations is not important.

Although the rest of this section is about string builders, it is equally applicable to string buffers.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint