I know that using a BufferedReader is quicker than using a Scanner since the Scanner reads and parses the Stream while the BufferedReader only reads the Stream.
However, I do not understand why the BufferedReader would still be quicker if I'm parsing the Stream after reading it from the BufferedReader, wouldn't this be essentially the same thing the Scanner is doing ? Both of them are reading and parsing, so why is the BufferedReader still quicker ?
Let's say I'm taking integers as an input:
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int x = Integer.parseInt(br.readLine());
System.out.println(x);
}
Won't this be the same as this:
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
System.out.println(x);
}
- So is my understanding of how this works correct ?
- Does the larger buffer size of the BufferedReader also help ?