The reset() method of the CharArrayWriter class in Java is used to reset the buffer so that it can be used again without throwing away the already allocated buffer.
Syntax:
public void reset()
Parameters: This method does not accept any parameter.
Return Value: This method does not returns anything.
Below program illustrate the above method:
Program 1:
// Java program to illustrate // the reset() method import java.io.*; public class GFG { public static void main(String[] args) throws IOException { // Initailizing the character array char[] geek = { 'G', 'E', 'E', 'K', 'S' }; // Initailizing the CharArrayWriter CharArrayWriter char_array1 = new CharArrayWriter(); for (int c = 72; c < 77; c++) { // Use of write(int char) // Writer int value to the Writer char_array1.write(c); } // Use of size() method System.out.println("\nSize of char_array1 : " + char_array1.size()); // Resets the current stream char_array1.reset(); // Use of size() method System.out.println("Size of char_array1 : " + char_array1.size()); } } |
Size of char_array1 : 5 Size of char_array1 : 0
Program 2:
// Java program to illustrate // the reset() method import java.io.*; public class GFG { public static void main(String[] args) throws IOException { // Initailizing the character array char[] geek = { 'G', 'O', 'P', 'A', 'L', 'L' }; // Initailizing the CharArrayWriter CharArrayWriter char_array1 = new CharArrayWriter(); for (int c = 72; c < 78; c++) { // Use of write(int char) // Writer int value to the Writer char_array1.write(c); } // Use of size() method System.out.println("\nSize of char_array1 : " + char_array1.size()); // Resets the current stream char_array1.reset(); // Use of size() method System.out.println("Size of char_array1 : " + char_array1.size()); } } |
Size of char_array1 : 6 Size of char_array1 : 0
Reference: https://docs.oracle.com/javase/10/docs/api/java/io/CharArrayWriter.html#reset()
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- CharArrayWriter close() method in Java with examples
- CharArrayWriter toCharArray() method in Java with examples
- CharArrayWriter write() method in Java with Examples
- CharArrayWriter flush() method in Java with examples
- CharArrayWriter toString() method in Java with examples
- CharArrayWriter append() method in Java with Examples
- CharArrayWriter writeTo() method in Java with Examples
- CharArrayWriter size() method in Java with examples
- MessageDigest reset() method in Java with Examples
- Reader reset() method in Java with Examples
- CharsetDecoder reset() method in Java with Examples
- LogManager reset() method in Java with Examples
- Matcher reset() method in Java with Examples
- PushbackReader reset() method in Java with Examples
- ByteArrayOutputStream reset() method in Java with Examples
- LongAccumulator reset() method in Java with examples
- CharArrayReader reset() method in Java with Examples
- CollationElementIterator reset() method in Java with Examples
- BufferedReader reset() method in Java with Examples
- CharsetEncoder reset() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

