Java.util.Scanner.useLocale() 方法
描述
java.util.Scanner.useLocale(Locale locale) 方法将此扫描仪的语言环境设置为指定的语言环境。
声明
以下是 java.util.Scanner.useLocale() 方法的声明
public Scanner useLocale(Locale locale)
参数
locale − 指定要使用的语言环境的字符串
返回值
此方法返回此扫描仪
异常
NA
示例
下面的例子展示了 java.util.Scanner.useLocale() 方法的使用。
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 the scanner
scanner.useLocale(Locale.ENGLISH);
// display the new locale
System.out.println("" + scanner.locale());
// close the scanner
scanner.close();
}
}
让我们编译并运行上面的程序,这将产生以下结果 −
Hello World! 3 + 3.0 = 6.0 true en

