Java Reference
In-Depth Information
Finally, Table 4-4 presents split() , a method that I employed in Chapter 3 ' s
StubFinder applicationtosplitastring'scomma-separatedlistofvaluesintoanarray
of String objects.Thismethodusesaregularexpressionthatidentifiesasequenceof
characters around which the string is split. (I discuss regular expressions in Appendix
C.)
Note StringIndexOutOfBoundsException and ArrayIn-
dexOutOfBoundsException are sibling classes that share a common
java.lang.IndexOutOfBoundsException superclass.
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
StringBuffer butcannotbeusedinthecontextofmultiplethreadswithoutexplicit
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.
Search WWH ::




Custom Search