- Java.util - WeakHashMap
- Java.util - Vector
- Java.util - UUID
- Java.util - TreeSet
- Java.util - TreeMap
- Java.util - TimeZone
- Java.util - TimerTask
- Java.util - Timer
- Java.util - StringTokenizer
- Java.util - Stack
- Java.util - SimpleTimeZone
- Java.util - ServiceLoader
- Java.util - Scanner
- Java.util - ResourceBundle.Control
- Java.util - ResourceBundle
- Java.util - Random
- Java.util - PropertyResourceBundle
- Java.util - PropertyPermission
- Java.util - Properties
- Java.util - PriorityQueue
- Java.util - Observable
- Java.util - Locale
- Java.util - ListResourceBundle
- Java.util - LinkedList
- Java.util - LinkedHashSet
- Java.util - LinkedHashMap
- Java.util - IdentityHashMap
- Java.util - Hashtable
- Java.util - HashSet
- Java.util - HashMap
- Java.util - GregorianCalendar
- Java.util - Formatter
- Java.util - EnumSet
- Java.util - EnumMap
- Java.util - Dictionary
- Java.util - Date
- Java.util - Currency
- Java.util - Collections
- Java.util - Calendar
- Java.util - BitSet
- Java.util - Arrays
- Java.util - ArrayList
- Java.util - ArrayDeque
- Java.util - Home
Java.util Package Extras
- Java.util - Discussion
- Java.util - Useful Resources
- Java.util - Enumerations
- Java.util - Exceptions
- Java.util - Interfaces
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java.util.Scanner Class
Introduction
The java.util.Scanner class is a simple text scanner which can parse primitive types and strings using regular expressions.Following are the important points about Scanner −
A Scanner breaks its input into tokens using a depmiter pattern, which by default matches whitespace.
A scanning operation may block waiting for input.
A Scanner is not safe for multithreaded use without external synchronization.
Class declaration
Following is the declaration for java.util.Scanner class −
pubpc final class Scanner extends Object implements Iterator<String>
Class constructors
Sr.No. | Constructor & Description |
---|---|
1 | Scanner(File source) This constructs a new Scanner that produces values scanned from the specified file. |
2 | Scanner(File source, String charsetName) This constructs a new Scanner that produces values scanned from the specified file. |
3 | Scanner(InputStream source) This constructs a new Scanner that produces values scanned from the specified input stream. |
4 | Scanner(InputStream source, String charsetName) This constructs a new Scanner that produces values scanned from the specified input stream. |
5 | Scanner(Readable source) This constructs a new Scanner that produces values scanned from the specified source. |
6 | Scanner(ReadableByteChannel source) This constructs a new Scanner that produces values scanned from the specified channel. |
7 | Scanner(ReadableByteChannel source, String charsetName) This constructs a new Scanner that produces values scanned from the specified channel. |
8 | Scanner(String source) This constructs a new Scanner that produces values scanned from the specified string. |
Class methods
Sr.No. | Method & Description |
---|---|
1 | This method closes this scanner. |
2 | This method returns the Pattern this Scanner is currently using to match depmiters. |
3 | This method attempts to find the next occurrence of the specified pattern ignoring depmiters. |
4 | This method attempts to find the next occurrence of a pattern constructed from the specified string, ignoring depmiters. |
5 | This method attempts to find the next occurrence of the specified pattern. |
6 | This method attempts to find the next occurrence of a pattern constructed from the specified string, ignoring depmiters. |
7 | This method returns true if this scanner has another token in its input. |
8 | This method returns true if the next complete token matches the specified pattern. |
9 | This method returns true if the next token matches the pattern constructed from the specified string. |
10 | This method returns true if the next token in this scanner s input can be interpreted as a BigDecimal using the nextBigDecimal() method. |
11 | This method returns true if the next token in this scanner s input can be interpreted as a BigInteger in the default radix using the nextBigInteger() method. |
12 | This method returns true if the next token in this scanner s input can be interpreted as a BigInteger in the specified radix using the nextBigInteger() method. |
13 | This method returns true if the next token in this scanner s input can be interpreted as a boolean value using a case insensitive pattern created from the string "true|false". |
14 | This method returns true if the next token in this scanner s input can be interpreted as a byte value in the default radix using the nextByte() method. |
15 | This method returns true if the next token in this scanner s input can be interpreted as a byte value in the specified radix using the nextByte() method. |
16 | This method returns true if the next token in this scanner s input can be interpreted as a double value using the nextDouble() method. |
17 | This method Returns true if the next token in this scanner s input can be interpreted as a float value using the nextFloat() method. |
18 | This method returns true if the next token in this scanner s input can be interpreted as an int value in the default radix using the nextInt() method. |
19 | This method returns true if the next token in this scanner s input can be interpreted as an int value in the specified radix using the nextInt() method. |
20 | This method returns true if there is another pne in the input of this scanner. |
21 | This method returns true if the next token in this scanner s input can be interpreted as a long value in the default radix using the nextLong() method. |
22 | This method returns true if the next token in this scanner s input can be interpreted as a long value in the specified radix using the nextLong() method. |
23 | This method returns true if the next token in this scanner s input can be interpreted as a short value in the default radix using the nextShort() method. |
24 | This method returns true if the next token in this scanner s input can be interpreted as a short value in the specified radix using the nextShort() method. |
25 | This method returns the IOException last thrown by this Scanner s underlying Readable. |
26 | This method returns this scanner s locale. |
27 | This method returns the match result of the last scanning operation performed by this scanner. |
28 | This method finds and returns the next complete token from this scanner. |
29 | This method returns the next token if it matches the specified pattern. |
30 | This method returns the next token if it matches the pattern constructed from the specified string. |
31 | This method scans the next token of the input as a BigDecimal. |
32 | This method Scans the next token of the input as a BigInteger. |
33 | This method scans the next token of the input as a BigInteger. |
34 | This method scans the next token of the input into a boolean value and returns that value. |
35 | This method scans the next token of the input as a byte. |
36 | This method scans the next token of the input as a byte. |
37 | This method scans the next token of the input as a double. |
38 | This method scans the next token of the input as a float. |
39 | This method scans the next token of the input as an int. |
40 | This method scans the next token of the input as an int. |
41 | This method advances this scanner past the current pne and returns the input that was skipped. |
42 | This method scans the next token of the input as a long. |
43 | This method scans the next token of the input as a long. |
44 | This method scans the next token of the input as a short. |
45 | This method scans the next token of the input as a short. |
46 | This method returns this scanner s default radix. |
47 | The remove operation is not supported by this implementation of Iterator. |
48 | This method resets this scanner. |
49 | This method skips input that matches the specified pattern, ignoring depmiters. |
50 | This method skips input that matches a pattern constructed from the specified string. |
51 | This method returns the string representation of this Scanner. |
52 | This method sets this scanner s depmiting pattern to the specified pattern. |
53 | This method sets this scanner s depmiting pattern to a pattern constructed from the specified String. |
54 | This method sets this scanner s locale to the specified locale. |
55 | This method Sets this scanner s default radix to the specified radix. |
Methods inherited
This class inherits methods from the following classes −
java.util.Object