Recently I have modified my code to
Scanner
to BufferedInputStream
. BufferedReader
which takes the input from any InputStreamReader
. This InputStreamReader
can be used with System.in
to take STDIN
input.BufferedInputStream
has read()
method, which further needs to be parsed according to the objective. In my case first i need to take an integer (let say n) as input from STDIN
after that a for loop
will take n strings as input. These strings have at max 1,00,000 characters.
Question is : Which one among Scanner
, BufferedInputStream
and BufferedReader
performs better for my objective?
Scanner was designed to simplify acceptance of input parameters at run time from user. This is the java equivalent of scanf()/getc()/cin. The 'Reader's are used to read character data, 'Stream's for streamed data. Scanner is best suited for your purpose. As it is simple to code and use.