Java.util.Scanner.reset() Method
Advertisements
Description
The java.util.Scanner.reset() method resets this scanner.Resetting a scanner discards all of its explicit state information which may have been changed by invocations of useDelimiter(java.util.regex.Pattern), useLocale(java.util.Locale), or useRadix(int).
Declaration
Following is the declaration for java.util.Scanner.reset() method
public Scanner reset()
Parameters
NA
Return Value
This method returns this scanner
Exception
NA
Example
The following example shows the usage of java.util.Scanner.reset() method.
package com.tutorialspoint;
import java.util.*;
public class ScannerDemo {
public static void main(String[] args) {
String s = "Hello World! 3 + 3.0 = 6.0 true ";
// create a new scanner with the specified String Object
Scanner scanner = new Scanner(s);
// print a line of the scanner
System.out.println("" + scanner.nextLine());
// change the locale of this scanner
scanner.useLocale(Locale.US);
// change the radix of this scanner
scanner.useRadix(30);
// reset and check the values for radix and locale, which are the default
scanner.reset();
System.out.println("" + scanner.radix());
System.out.println("" + scanner.locale());
// close the scanner
scanner.close();
}
}
Let us compile and run the above program, this will produce the following result:
Hello World! 3 + 3.0 = 6.0 true 10 el_GR