System.in. read() or still Scanner?

Noticed in many books used: System.in.read() is to get something from the keyboard. Why is the Scanner class not used there? Because System.in.read() is faster than creating an instance of the Scanner class and then creating a construct like this:

Scanner scanner = new Scanner(System.in);
String name = scanner.nextLine();

Or

Scanner scanner = new Scanner(System.in);
int x = scanner.nextInt();

I searched on Stackoverflow and didn't find any differences between System.in.read and the Scanner class.

Author: A K, 2018-11-02

2 answers

There is a difference, and a significant one at that. System.in.read() can only count 1 a character in the form of char.
At the same time, Scanner is a universal thing that allows you to read in the format that you need.
If you want to count by characters, then you should not bother, but use System.in.read(). In other cases, these are, in particular, files, we use Scanner.

 10
Author: michael_best, 2018-11-02 07:21:33

Because the art of presenting educational information includes the ability to tell only about what is relevant to the topic, without involving additional entities. If the topic relates to the basics of reading data from the input stream, then explaining it through the use of a tokenizer is a complication and a distraction.

 6
Author: Sergey Gornostaev, 2018-11-02 07:22:07