Java StringWriter toString() Example
StringWriter class toString() method example. This example shows you how to use toString() method.
Syntax is : public String toString()
This method return the buffer's current value as a string.
Here is the code.
/**
* @(#) ToStringStringWriter.java
* A class representing use of method toString() of StringWriter class in
java.io Package.
* @Version 29-May-2008
* @author Rose India Team
*/
import java.io.*;
public class ToStringStringWriter {
public static void main(String[] args){
// Create object of StringWriter class
StringWriter objStringWriter = new StringWriter();
// append() method call.
objStringWriter.append("Rose ");
objStringWriter.append("India");
System.out.println("String in string buffer is : " + objStringWriter);
// toString() method call.
String strValue = objStringWriter.toString();
System.out.println("String value of String Buffer is : " + strValue);
}
} |
Output of the program.
String in string buffer is : Rose India
String value of String Buffer is : Rose India |
|