Figure 4.18. Comparing the replace methods in String (left) and StringBuilder (right). The method replace in String accepts the characters to be replaced. The method replace in StringBuilder accepts a position to be replaced.

SubSequence()

Apart from using the method substring, you can also use the method subSequence to retrieve a subsequence of a StringBuilder object. This method returns objects of type CharSequence:

The method subsequence doesn’t modify the existing value of a StringBuilder object.

4.2.4. A quick note on the class StringBuffer ...

Get OCA Java SE 7 Programmer I Certification Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.