Scanner Class in Java With Examples

Scanner class in Java (java.util.Scanner) was introduced in Java 1.5 as a simple text scanner which can parse primitive types and strings using regular expressions.

Scanner Class in Java

Java Scanner class can be used to break the input into tokens with any regular expression delimiter and it’s good for parsing files also.

Scanner class can be used to read file data into primitive. It also extends String split() method to return tokens as String, int, long, Integer and other wrapper classes.

Java Scanner Example

Here I am using Scanner to read a file line by line, parsing a CSV file to create java object easily and read from the user input.

JavaFileScanner.java

Output of the above program is:

We can use java Scanner class to parse the input into specific datatype tokens.

Read this post to learn how to read CSV File using Scanner.

Reference: API Doc

By admin

Leave a Reply

%d bloggers like this: