Java Utility Library

Java Scanner - reset() Method



The java.util.Scanner.reset() method is used to reset the 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).

Syntax

public Scanner reset()

Parameters

No parameter is required.

Return Value

Returns the scanner.

Exception

NA.

Example:

In the example below, the java.util.Scanner.reset() method is used to reset the scanner.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {

    //String to scan
    String MyString = "Hello World 10 + 20 = 30.0";

    //creating a Scanner
    Scanner MyScan = new Scanner(MyString);

    //set the scanner's locale to GERMAN
    Locale locale = new Locale("GERMANY", "GERMAN");
    MyScan.useLocale(locale);

    //print the new locale
    System.out.println(MyScan.locale());

    //reset the scanner
    MyScan.reset();

    //print the default locale
    System.out.println(MyScan.locale());

    //close the scanner
    MyScan.close();
  }
}

The output of the above code will be:

germany_GERMAN
en_US

❮ Java.util - Scanner