Scanner reset() method in Java with Examples Last Updated : 11 Oct, 2018 Comments Improve Suggest changes Like Article Like Report The reset() method of java.util.Scanner class resets this scanner. On resetting a scanner, it 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() Return Value: This function returns this scanner which has been reset. Below programs illustrate the above function: Program 1: Java // Java program to illustrate the // reset() method of Scanner class in Java import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { String s = "Geeksforgeeks has Scanner Class Methods"; // create a new scanner // with the specified String Object Scanner scanner = new Scanner(s); // print a line of the scanner System.out.println("Scanner String:\n" + scanner.nextLine()); // change the locale of this scanner scanner.useLocale(Locale.US); // change the radix of this scanner scanner.useRadix(30); System.out.println("\nBefore Reset:\n"); // print the values before reset System.out.println("Radix: " + scanner.radix()); System.out.println("Locale: " + scanner.locale()); // reset scanner.reset(); System.out.println("\nAfter Reset:\n"); System.out.println("Radix: " + scanner.radix()); System.out.println("Locale: " + scanner.locale()); // close the scanner scanner.close(); } } Output: Scanner String: Geeksforgeeks has Scanner Class Methods Before Reset: Radix: 30 Locale: en_US After Reset: Radix: 10 Locale: en_US Program 2: Java // Java program to illustrate the // reset() method of Scanner class in Java import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { String s = "Geeksforgeeks"; // create a new scanner // with the specified String Object Scanner scanner = new Scanner(s); // print a line of the scanner System.out.println("Scanner String:\n" + scanner.nextLine()); // change the locale of this scanner scanner.useLocale(Locale.US); // change the radix of this scanner scanner.useRadix(12); System.out.println("\nBefore Reset:\n"); // print the values before reset System.out.println("Radix: " + scanner.radix()); System.out.println("Locale: " + scanner.locale()); // reset scanner.reset(); System.out.println("\nAfter Reset:\n"); System.out.println("Radix: " + scanner.radix()); System.out.println("Locale: " + scanner.locale()); // close the scanner scanner.close(); } } Output: Scanner String: Geeksforgeeks Before Reset: Radix: 12 Locale: en_US After Reset: Radix: 10 Locale: en_US Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#reset() Comment More infoAdvertise with us Next Article Scanner reset() method in Java with Examples gopaldave Follow Improve Article Tags : Java Java - util package Java-I/O Java-Functions Practice Tags : Java Similar Reads Scanner nextShort() method in Java with Examples The nextShort(radix) method of java.util.Scanner class scans the next token of the input as a short. If the translation is successful, the scanner advances past the input that matched. If the parameter radix is not passed, then it behaves similarly as nextShort(radix) where the radix is assumed to b 5 min read Scanner nextInt() method in Java with Examples The nextInt(radix) method of java.util.Scanner class scans the next token of the input as a Int. If the translation is successful, the scanner advances past the input that matched. If the parameter radix is not passed, then it behaves similarly as nextInt(radix) where the radix is assumed to be the 5 min read Scanner radix() method in Java with Examples The radix() method of java.util.Scanner class returns this scanner's default radix. Syntax: public int radix() Return Value: This function returns the default radix of this scanner. Below programs illustrate the above function: Program 1: Java // Java program to illustrate the // radix() method of S 2 min read Scanner nextLine() method in Java with Examples The nextLine() method of java.util.Scanner class advances this scanner past the current line and returns the input that was skipped. This function prints the rest of the current line, leaving out the line separator at the end. The next is set to after the line separator. Since this method continues 2 min read Scanner nextByte() method in Java with Examples The nextByte(radix) method of java.util.Scanner class scans the next token of the input as a Byte. If the translation is successful, the scanner advances past the input that matched. If the parameter radix is not passed, then it behaves similarly as nextByte(radix) where the radix is assumed to be t 5 min read Scanner nextLong() method in Java with Examples The nextLong(radix) method of java.util.Scanner class scans the next token of the input as a long. If the translation is successful, the scanner advances past the input that matched. If the parameter radix is not passed, then it behaves similarly as nextLong(radix) where the radix is assumed to be t 5 min read Scanner nextFloat() method in Java with Examples The nextFloat() method of java.util.Scanner class scans the next token of the input as a Float(). If the translation is successful, the scanner advances past the input that matched. Syntax: public float nextFloat() Parameters: The function does not accepts any parameter. Return Value: This function 4 min read Scanner nextDouble() method in Java with Examples The nextDouble() method of java.util.Scanner class scans the next token of the input as a Double. If the translation is successful, the scanner advances past the input that matched. Syntax: public double nextDouble() Parameters: The function does not accepts any parameter. Return Value: This functio 4 min read Scanner nextBoolean() method in Java with Examples The nextBoolean() method of java.util.Scanner class scans the next token of the input as a Boolean. If the translation is successful, the scanner advances past the input that matched. Syntax: public boolean nextBoolean() Parameters: The function does not accepts any parameter. Return Value: This fun 4 min read Scanner skip() method in Java with Examples skip(Pattern pattern) The skip(Pattern pattern) method of java.util.Scanner class skips input that matches the specified pattern, ignoring the delimiters. The function skips the input if an anchored match of the specified pattern succeeds it. Syntax: public Scanner skip(Pattern pattern) Parameters: 5 min read Like