Java.io.StringWriter.append() Method
Advertisements
Description
The java.io.StringWriter.append() method appends the specified character sequence to this writer.
Declaration
Following is the declaration for java.io.StringWriter.append() method
public StringWriter append(CharSequence csq)
Parameters
csq -- The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.
Return Value
This method returns this writer.
Exception
NA
Example
The following example shows the usage of java.io.StringWriter.append() method.
package com.tutorialspoint;
import java.io.*;
public class StringWriterDemo {
public static void main(String[] args) {
// create a new writer
StringWriter sw = new StringWriter();
// create two new sequences
CharSequence sq1 = "Hello";
CharSequence sq2 = " World";
// append sequence
sw.append(sq1);
// print result
System.out.println("" + sw.toString());
// append second sequence
sw.append(sq2);
// print result again
System.out.println("" + sw.toString());
}
}
Let us compile and run the above program, this will produce the following result
Hello Hello World