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
import java.io.*;
public class GFG {
public static void main(String[] args)
throws IOException
{
char [] geek = { 'G' , 'E' , 'E' , 'K' , 'S' };
CharArrayWriter char_array1
= new CharArrayWriter();
for ( int c = 72 ; c < 77 ; c++) {
char_array1.write(c);
}
System.out.println( "\nSize of char_array1 : "
+ char_array1.size());
char_array1.reset();
System.out.println( "Size of char_array1 : "
+ char_array1.size());
}
}
|
Output:
Size of char_array1 : 5
Size of char_array1 : 0
Program 2:
Java
import java.io.*;
public class GFG {
public static void main(String[] args)
throws IOException
{
char [] geek
= { 'G' , 'O' , 'P' , 'A' , 'L' , 'L' };
CharArrayWriter char_array1
= new CharArrayWriter();
for ( int c = 72 ; c < 78 ; c++) {
char_array1.write(c);
}
System.out.println( "\nSize of char_array1 : "
+ char_array1.size());
char_array1.reset();
System.out.println( "Size of char_array1 : "
+ char_array1.size());
}
}
|
Output:
Size of char_array1 : 6
Size of char_array1 : 0
Reference: https://docs.oracle.com/javase/10/docs/api/java/io/CharArrayWriter.html#reset()
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
25 Jun, 2021
Like Article
Save Article