Java.io.StringWriter.append() Method



Description

The java.io.StringWriter.append() method appends the specified character to this writer.

Declaration

Following is the declaration for java.io.StringWriter.append() method.

public StringWriter append(char c)

Parameters

c − The 16-bit character to append.

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();

      // append a char       
      System.out.println("" + sw.append("a"));
      System.out.println("" + sw.append("b"));
   }
}

Let us compile and run the above program, this will produce the following result −

a
ab
java_io_stringwriter.htm
Advertisements