Java String Buffer Example

String buffer class example. This example shows you how to use append method in different cases.


String buffer class example. This example shows you how to use append method in different cases.

Here is the full code:
/**
 * @(#)  AppendString. java
 * A class representing append method
 * @Version  01-May-2008
 @author   Rose India Team
 */

class AppendString{
  public static void main(String[] args){

    StringBuffer sb = new StringBuffer("ABC");

    //Appends the boolean argument as string to the string buffer.
    sb.append(true);
    System.out.println(sb);
    
    //Appends the string to this string buffer.
    sb.append("ABC");
    System.out.println(sb);

    //Appends the string representation of a subarray of the char array argument to this string buffer.
    char[] str=new char[]{'D','E','F','G','H','I','J'};
    sb.append(str,2,5);
    System.out.println(sb);

    //Appends the char argument to the string buffer.
    sb.append('D');
    System.out.println(sb);

    //Appends double argument to the string buffer.
    double d=10.100000001;
    sb.append(d);
    System.out.println(sb);

    //Appends the float argument to the string buffer.
    sb.append(5.5);
    System.out.println(sb);

    //Appends the int argument to the string buffer.
    sb.append(2);
    System.out.println(sb);

    //Appends the long argument to the string buffer.
    long l =1000;
    sb.append(l);
    System.out.println(sb);

    //Appends the specified StringBuffer to this StringBuffer.
    sb.append(new StringBuffer("GHI"));
    System.out.println(sb);

    //Appends the Object argument to the string buffer.
    sb.append(sb);
    System.out.println(sb);
  }
}

null

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US