java – or still Scanner?


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

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


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

I searched on Stackoverflow and did not find the difference between and the Scanner class.


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

Scroll to Top