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();
- Get certified in first attempt download master-ciw-enterprise-developer - Master CIW Enterprise Developer simulation.
- Click here to download scbcd test study guide and practice question.
- Become SUN SCDJWS certified.
- Click here to download scjp test study guide and practice question.
- Get certified in first attempt download scjp-5-0 - SCJP 5/6 simulation.
- Best exam simulation SUN scmad download free trial.
- Download free practice test for SUN SCWCD exam.
- Best exam simulation SUN CX310-055 download free trial.
- Download practice question and study guide for CX310-056 for exam.
- Get certified in first attempt download CX310-065 - SCJP 6.0 simulation.
- Download practice question and study guide for CX310-066 for exam.
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.
