Java Scanner class
There are various ways to read input from the keyboard, the java.util.Scanner class is one of them.
The Java Scanner class breaks the input into tokens using a delimiter that is whitespace bydefault. It provides many methods to read and parse various primitive values.
Java Scanner class is widely used to parse text for string and primitive types using regular expression.
Java Scanner class extends Object class and implements Iterator and Closeable interfaces.
Commonly used methods of Scanner class
There is a list of commonly used Scanner class methods:
Java Scanner Example to get input from console
Let's see the simple example of the Java Scanner class which reads the int, string and double value as an input:
Enter your rollno 111 Enter your name Ratan Enter 450000 Rollno:111 name:Ratan fee:450000
Java Scanner Example with delimiter
Let's see the example of Scanner class with delimiter. The \s represents whitespace.
10 tea 20 coffee