Tuesday, August 1, 2017

CharArrayWriter - Initial Array Size

Setting Initial char Array Size

The Java CharArrayWriter has a constructor that lets you set the initial size of the char array used internally to store the written characters.
Setting the initial size does not prevent the CharArrayWriter from storing more characters than the initial size. If the number of characters written to the CharArrayWriter exceed the size of the initial char array, a new char array is created, and all characters are copied into the new array.
Here is how setting the initial char array size using the CharArrayWriter constructor looks:
int initialSize = 1024;

CharArrayWriter charArrayWriter =
    new CharArrayWriter(initialSize);
This example creates a CharArrayWriter with an initial char array size of 1024.

@reference_1_tutorials.jenkov.com
Java IO: CharArrayWriter

No comments:

Post a Comment