Java Scanner reset()方法

java.util.Scanner.reset() 方法重置该扫描仪。重设scanner 丢弃所有的这些可能已被useDelimiter(java.util.regex.Pattern)的调用改变其明确的状态信息,useLocale(java.util.Locale),或useRadix(int)。

1 语法

public Scanner reset()

2 参数

3 返回值

此方法返回此scanner。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.util.Scanner.reset()方法的例子
 */
import java.util.*;

public class Demo {
    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();
    }
}

输出结果为:

Hello World! 3 + 3.0 = 6.0 true 
10
zh_CN

热门文章

优秀文章