14.4.5 StringBuilder Insertion and Deletion Methods

StringBuilder provides overloaded insert methods to insert values of various types at any position in a StringBuilder. Versions are provided for the primitive types and for character arrays, Strings, Objects and CharSequences. Each method takes its second argument and inserts it at the index specified by the first argument. If the first argument is less than 0 or greater than the StringBuilder’s length, a StringIndexOutOfBoundsException occurs. Class StringBuilder also provides methods delete and deleteCharAt to delete characters at any position in a StringBuilder. Method delete takes two arguments—the starting index and the index one past the end of the characters to delete. All characters ...

Get Java™ How To Program (Early Objects), Tenth Edition 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.