java.util.Scanner類的locale()方法返回此掃描器的語言環境。
用法:
public Locale locale()
參數:該函數不接受任何參數。
返回值:此函數返回此掃描儀的語言環境
以下示例程序旨在說明上述函數:
示例1:
// Java program to illustrate the
// locale() method of Scanner class in Java
// without parameter
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
String s = "Gfg Geeks GeeksForGeeks";
// create a new scanner
// with the specified String Object
Scanner scanner = new Scanner(s);
// print the locale
System.out.println(scanner.locale());
scanner.close();
}
}
輸出:
en_US
示例2:
// Java program to illustrate the
// locale() method of Scanner class in Java
// without parameter
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
String s = "121324";
// create a new scanner
// with the specified String Object
Scanner scanner = new Scanner(s);
// print the locale
System.out.println(scanner.locale());
scanner.close();
}
}
輸出:
en_US
參考: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#locale()
相關用法
- Java TimeZone getDisplayName(Locale locale)用法及代碼示例
- Java Locale.Builder setLocale(Locale)用法及代碼示例
- Java Locale getDisplayVariant(Locale inLoc)用法及代碼示例
- Java Locale getDisplayLanguage(Locale)用法及代碼示例
- Java Locale getDisplayName(Locale)用法及代碼示例
- Java Locale getDisplayCountry(Locale)用法及代碼示例
- Java Scanner nextInt()用法及代碼示例
- Java Scanner nextLong()用法及代碼示例
- Java Scanner nextDouble()用法及代碼示例
- Java Scanner nextBoolean()用法及代碼示例
- Java Scanner nextBigDecimal()用法及代碼示例
- Java Scanner nextLine()用法及代碼示例
- Java Scanner useDelimiter()用法及代碼示例
- Java Scanner delimiter()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Scanner locale() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。