Javadoc of java.util.Scanner :
A simple text scanner which can parse primitive types and strings using regular expressions.
A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods (nextInt(), nextByte(), nextFloat(), next(), nextLine()).
Sample Code:
Scanner s = new Scanner(System.in);
System.out.println("Enter an int value : ");
int i = s.nextInt();
System.out.println("Value of i = " + i);
System.out.println("Enter a float value : ");
float f = s.nextFloat();
System.out.println("Value of f = " + f);
System.out.println("Enter a String value : ");
String str = s.next();
System.out.println("Value of str = " + str);
s.nextLine();
System.out.println("Enter a line : ");
String line = s.nextLine();
System.out.println("Input Line = " + line);
SCANNER CAN BE CREATED USING DIFFERENT SOURCE:
Scanner(File source)
Scanner(InputStream source) : its used in our example
Scanner(Path source)
Scanner(ReadableByteChannel source)
Scanner(String source)