of String objects.Thismethodusesaregularexpressionthatidentifiesasequenceof
characters around which the string is split. (I discuss regular expressions in Appendix
Note StringIndexOutOfBoundsException and ArrayIn-
dexOutOfBoundsException are sibling classes that share a common
StringBuffer and StringBuilder
String objects are immutable: you cannot modify a String object's string. The
various String methods that appear to modify the String object actually return
a new String object with modified string content instead. Because returning new
String objects is often wasteful, Java provides the java.lang.StringBuffer
and java.lang.StringBuilder classes as a workaround. These classes are
identicalapartfromthefactthat StringBuffer canbeusedinthecontextofmultiple
threads (discussed later in this chapter), and that StringBuilder is faster than
synchronization (also discussed later in this chapter).
Table4-5 describessomeof StringBuffer 'sconstructorsandmethodsforinitial-
izing StringBuffer objects and working with string buffers. StringBuilder 's
constructors and methods are identical.