14.4.4 StringBuilder append Methods

Class StringBuilder provides overloaded append methods (Fig. 14.13) to allow values of various types to be appended to the end of a StringBuilder. Versions are provided for each of the primitive types and for character arrays, Strings, Objects, and more. (Remember that method toString produces a string representation of any Object.) Each method takes its argument, converts it to a string and appends it to the StringBuilder.

 1   // Fig. 14.13: StringBuilderAppend.java 2   // StringBuilder append methods. 3  4   public class StringBuilderAppend 5   { 6      public static void main(String[] args) 7      { 8         Object objectRef = "hello"9         String string = "goodbye" ...

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.