CharArrayWriter size() method in Java with examples
Last Updated :
28 Jun, 2021
The size() method of the CharArrayWriter class in Java is used to get the current size of the buffer.
Syntax:
public int size()
Parameters: This method does not accept any parameter.
Return Value: This method returns an integer value which signifies the current size of the buffer.
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());
}
}
|
Output:
Size of char_array1 : 5
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());
}
}
|
Output:
Size of char_array1 : 6
Reference: https://docs.oracle.com/javase/10/docs/api/java/io/CharArrayWriter.html#size()
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...