Recently I have modified my code to
- While taking input form STDIN, I moved from
ScannertoBufferedInputStream. - I also read about
BufferedReaderwhich takes the input from anyInputStreamReader. ThisInputStreamReadercan be used withSystem.into takeSTDINinput. BufferedInputStreamhasread()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.