Scanner is a class present in the java.util package. Like the BufferedReader class, this class is used to take user inputs. However, unlike BufferedReader, which throws checked IOException, it does not throw any checked exception. In addition to taking an input from the user, it is also used to parse through the elements of the code. This class contains the hasNext, hasNextLine, hasNextInt, and hasNextDouble methods to check whether any more element is present. It throws an unchecked InputMismatchException, if the next token is not of the correct type.
Example:
Scanner s= new Scanner(System.in);
String str= s.next();
int nextvalue=s.nextInt();
s.close();
- Download free practice test for CIW Master CIW Enterprise Developer exam.
- Download free practice test for scbcd SCBCD exam.
- Pass SCDJWS in first attampt.
- Click here to get free scjp SCJP exam practice questions.
- Become SUN SCJP 5/6 certified.
- Become SUN SCMAD certified.
- Pass SUN scwcd - SCWCD
- Click here to get free CX310-055 Java 5.0 exam practice questions.
- Download free practice test for CX310-056 SCJP 5.0 Java Upgrade exam.
- Pass SCJP 6.0 in first attampt.
- Pass SUN CX310-066 - SCJP Upgrade
If you like this article, please leave a comment or subscribe this blog via RSS or via e-mail, Bookmark and share through your network. Click the AddThis button below. Thanks.