Source of StringBufferAppend.java


  1: // Fig. 29.13: StringBufferAppend.java
  2: // StringBuffer append methods.
  3: 
  4: public class StringBufferAppend 
  5: {
  6:    public static void main( String args[] )
  7:    {
  8:       Object objectRef = "hello"; 
  9:       String string = "goodbye";  
 10:       char charArray[] = { 'a', 'b', 'c', 'd', 'e', 'f' };
 11:       boolean booleanValue = true;
 12:       char characterValue = 'Z';
 13:       int integerValue = 7;
 14:       long longValue = 10000000000L;
 15:       float floatValue = 2.5f; // f suffix indicates 2.5 is a float
 16:       double doubleValue = 33.333;
 17: 
 18:       StringBuffer lastBuffer = new StringBuffer( "last StringBuffer" );
 19:       StringBuffer buffer = new StringBuffer();
 20: 
 21:       buffer.append( objectRef );
 22:       buffer.append( "\n" ); // each of these contains new line
 23:       buffer.append( string );
 24:       buffer.append( "\n" );
 25:       buffer.append( charArray );
 26:       buffer.append( "\n" );
 27:       buffer.append( charArray, 0, 3 );
 28:       buffer.append( "\n" );
 29:       buffer.append( booleanValue );
 30:       buffer.append( "\n" );
 31:       buffer.append( characterValue );
 32:       buffer.append( "\n" );
 33:       buffer.append( integerValue );
 34:       buffer.append( "\n" );
 35:       buffer.append( longValue );
 36:       buffer.append( "\n" );
 37:       buffer.append( floatValue );
 38:       buffer.append( "\n" );
 39:       buffer.append( doubleValue );
 40:       buffer.append( "\n" );
 41:       buffer.append( lastBuffer );
 42: 
 43:       System.out.printf( "buffer contains %s\n", buffer.toString() );
 44:    } // end main
 45: } // end StringBufferAppend
 46: 
 47: /**************************************************************************
 48:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 49:  * Pearson Education, Inc. All Rights Reserved.                           *
 50:  *                                                                        *
 51:  * DISCLAIMER: The authors and publisher of this book have used their     *
 52:  * best efforts in preparing the book. These efforts include the          *
 53:  * development, research, and testing of the theories and programs        *
 54:  * to determine their effectiveness. The authors and publisher make       *
 55:  * no warranty of any kind, expressed or implied, with regard to these    *
 56:  * programs or to the documentation contained in these books. The authors *
 57:  * and publisher shall not be liable in any event for incidental or       *
 58:  * consequential damages in connection with, or arising out of, the       *
 59:  * furnishing, performance, or use of these programs.                     *
 60:  *************************************************************************/