BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
I just want to know how many characters I can put in when I use the above statement. For example, if I can put in "aaaaa" or "abcde" into console, that would mean I can put 5 or more characters. Then can I put in "a" 2,147,483,647 times? (max value of integer) System.in seems like internally storing the sequence of input as interger type.
If it is true, how many 2-byte characters can I put in? Is it 1,073,741,823? (the half of that number)
The maximum should not be limited by System.in, as it should block if it can't accept more characters, but by the readLine() method. If you take a look into the implementation of readLine(), you will see that the result is built via a StringBuffer. This holds the string to built in a char array. So the maximum number of characters to be returned is limited by the maximum length of a char array. (Which is Integer.MAX_VALUE - 5 according to: Do Java arrays have a maximum size?). If you add more characters, you will get an OOM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With