StringWriter toString Example

StringWriter class toString example. This example shows you how to use toString method.


StringWriter class toString example. This example shows you how to use toString method.method returns StringBuffer's value as String .

Here is the code:-
/**
 * @Program uses toString method to return StringBuffer's content as string;
 * ToString.java 
 * Author:-RoseIndia Team
 * Date:-9-july-2008
 */

import java.io.StringWriter;
import java.io.PrintWriter;

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

    StringWriter mega = new StringWriter();
    PrintWriter micro = new PrintWriter(mega);
    StringBuffer santhorus = new StringBuffer(micro.toString());

    micro.print("programmers line");

    // StringWriter pico = new StringWriter();

    santhorus = new StringBuffer(micro.toString());
    micro.append(" bond ");

    santhorus = new StringBuffer(micro.toString());
    micro.write(007);

    santhorus = new StringBuffer(micro.toString());
    micro.print("  roseindia.net");
    System.out.println(mega);
  }
}

Output of the program:-
programmers line bond   roseindia.net

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

HOME | COPYRIGHT | CONTACT US