# Class StringWriter

java.lang.Object
java.io.Writer
java.io.StringWriter

All Implemented Interfaces:
  `java.io.Closeable, java.io.Flushable, Appendable, AutoCloseable`

public class StringWriter extends java.io.Writer implements Appendable

- ## Field Summary

  ### Fields inherited from class java.io.Writer

  `lock`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `StringWriter()`
  `StringWriter(int initialSize)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `StringWriter`
  `append(char c)`
  Appends the specified character.
  `StringWriter`
  `append(CharSequence csq)`
  Appends the character sequence `csq`.
  `StringWriter`
  `append(CharSequence csq, int start, int end)`
  Appends a subsequence of `csq`.
  `void`
  `close()`
  `void`
  `flush()`
  `StringBuffer`
  `getBuffer()`
  `String`
  `toString()`
  Returns a string representation of the object.
  `void`
  `write(char[] cbuf)`
  `void`
  `write(char[] cbuf, int off, int len)`
  `void`
  `write(int c)`
  `void`
  `write(String str)`
  `void`
  `write(String str, int off, int len)`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### StringWriter

    public StringWriter()

  - ### StringWriter

    public StringWriter(int initialSize)

- ## Method Details

  - ### close

    public void close() throws java.io.IOException
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `java.io.Closeable`
    Specified by:
      `close` in class `java.io.Writer`
    Throws:
      `java.io.IOException`

  - ### flush

    public void flush() throws java.io.IOException
    Specified by:
      `flush` in interface `java.io.Flushable`
    Specified by:
      `flush` in class `java.io.Writer`
    Throws:
      `java.io.IOException`

  - ### write

    public void write(char[] cbuf, int off, int len) throws java.io.IOException
    Specified by:
      `write` in class `java.io.Writer`
    Throws:
      `java.io.IOException`

  - ### write

    public void write(String str, int off, int len) throws java.io.IOException
    Overrides:
      `write` in class `java.io.Writer`
    Throws:
      `java.io.IOException`

  - ### write

    public void write(int c) throws java.io.IOException
    Overrides:
      `write` in class `java.io.Writer`
    Throws:
      `java.io.IOException`

  - ### write

    public void write(String str) throws java.io.IOException
    Overrides:
      `write` in class `java.io.Writer`
    Throws:
      `java.io.IOException`

  - ### write

    public void write(char[] cbuf) throws java.io.IOException
    Overrides:
      `write` in class `java.io.Writer`
    Throws:
      `java.io.IOException`

  - ### toString

    public String toString()
    Description copied from class: `Object`
    Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
    Overrides:
      `toString` in class `Object`

  - ### getBuffer

    public StringBuffer getBuffer()

  - ### append

    public StringWriter append(char c)
    Description copied from interface: `Appendable`

    Appends the specified character.

    ###### Parameters

    - `c`: the character to append.

    ###### Returns

    this `Appendable`.

    ###### Throws

    - `IOException`: if an I/O error occurs.
    Specified by:
      `append` in interface `Appendable`
    Overrides:
      `append` in class `java.io.Writer`

  - ### append

    public StringWriter append(CharSequence csq)
    Description copied from interface: `Appendable`

    Appends the character sequence `csq`. Implementation classes may not append the whole sequence, for example if the target is a buffer with limited size.

    If `csq` is `null`, the characters "null" are appended.

    ###### Parameters

    - `csq`: the character sequence to append.

    ###### Returns

    this `Appendable`.

    ###### Throws

    - `IOException`: if an I/O error occurs.
    Specified by:
      `append` in interface `Appendable`
    Overrides:
      `append` in class `java.io.Writer`

  - ### append

    public StringWriter append(CharSequence csq, int start, int end)
    Description copied from interface: `Appendable`

    Appends a subsequence of `csq`.

    If `csq` is not `null` then calling this method is equivalent to calling `append(csq.subSequence(start, end))`.

    If `csq` is `null`, the characters "null" are appended.

    ###### Parameters

    - `csq`: the character sequence to append.

    - `start`: @param start the first index of the subsequence of `csq` that is appended.

    - `end`: @param end the last index of the subsequence of `csq` that is appended.

    ###### Returns

    this `Appendable`.

    ###### Throws

    - `IndexOutOfBoundsException`: @throws IndexOutOfBoundsException if `start end` or `end` is greater than the length of `csq`.

    - `IOException`: if an I/O error occurs.

    Specified by:
      `append` in interface `Appendable`
    Overrides:
      `append` in class `java.io.Writer`