StringWriter flush() method in Java with Examples Last Updated : 29 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The flush() method of StringWriter Class in Java is used to flush the writer. By flushing the writer, it means to clear the writer of any element that may be or maybe not inside the writer. It neither accepts any parameter nor returns any value. Syntax: public void flush() Parameters: This method does not accepts any parameter. Return Value: This method does not returns any value. It just flushes the writer. Below programs illustrates the working of flush() method: Program 1: Java // Java program to demonstrate // StringWriter flush() method import java.io.*; class GFG { public static void main(String[] args) { // The string to be written in the writer String str = "GeeksForGeeks"; try { // Create a StringWriter instance StringWriter writer = new StringWriter(); // Write the above string to this writer // This will put the string in the writer // till it is printed on the console writer.write(str); System.out.println(writer.toString()); // Now clear the writer // using flush() method writer.flush(); } catch (Exception e) { System.out.println(e); } } } Output: GeeksForGeeks Program 2: Java // Java program to demonstrate // StringWriter flush() method import java.io.*; class GFG { public static void main(String[] args) { try { // Create a StringWriter instance StringWriter writer = new StringWriter(); // Write the char to this writer // This will put the char in the writer // till it is printed on the console writer.write(65); System.out.println(writer.toString()); // Now clear the writer // using flush() method writer.flush(); } catch (Exception e) { System.out.println(e); } } } Output: A Comment More infoAdvertise with us Next Article PrintStream flush() method in Java with Examples C code_r Follow Improve Article Tags : Java Java-Functions Java-IO package Java-StringWriter Practice Tags : Java Similar Reads PrintWriter flush() method in Java with Examples The flush() method of PrintWriter Class in Java is used to flush the stream. By flushing the stream, it means to clear the stream of any element that may be or maybe not inside the stream. It neither accepts any parameter nor returns any value. Syntax: public void flush() Parameters: This method do 2 min read PrintStream flush() method in Java with Examples The flush() method of PrintStream Class in Java is used to flush the stream. By flushing the stream, it means to clear the stream of any element that may be or maybe not inside the stream. It neither accepts any parameter nor returns any value. Syntax: public void flush() Parameters: This method do 2 min read StringWriter equals() method in Java with Example The Java.io.StringWriter.equals(Object obj) method of StringWriter class in Java is used to check whether the two instances of StringWriter are equal or not. It returns a boolean stating whether they are equal or not. Signature: public boolean equals(StringWriter second_StringWriter) Syntax: first_S 2 min read Writer flush() method in Java with Examples The flush() method of Writer Class in Java is used to flush the writer. By flushing the writer, it means to clear the writer of any element that may be or maybe not inside the writer. It neither accepts any parameter nor returns any value. Syntax: public void flush() Parameters: This method do not a 2 min read Writer write(String) method in Java with Examples The write(String) method of Writer Class in Java is used to write the specified String on the stream. This String value is taken as a parameter. Syntax: public void write(String string) Parameters: This method accepts a mandatory parameter string which is the String to be written in the Stream. Retu 2 min read StringWriter append(char) method in Java with Examples The append(char) method of StringWriter Class in Java is used to append the specified char value on the writer. This char value is taken as a parameter. Syntax: public void append(char charValue) Parameters: This method accepts a mandatory parameter charValue which is the char value to be appended o 2 min read Like