
- Java.util 包類
- Java.util - 首頁
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util 包其他內容
- Java.util - 介面
- Java.util - 異常
- Java.util - 列舉
- Java.util 有用資源
- Java.util - 有用資源
- Java.util - 討論
Java Locale getCountry() 方法
描述
Java Locale getCountry() 方法返回此區域設定的國家/地區程式碼,該程式碼將為空字串或大寫的 ISO 3166 2 字母程式碼。
宣告
以下是 java.util.Locale.getCountry() 方法的宣告
public String getCountry()
引數
無
返回值
此方法不返回值。
異常
無
從 US 區域設定獲取國家示例
以下示例演示了 Java Locale getCountry() 方法的使用。我們正在建立一個 US 區域設定,然後檢索並列印其國家/地區。
package com.tutorialspoint; import java.util.Locale; public class LocaleDemo { public static void main(String[] args) { // create a new locale Locale locale = Locale.US; // print this locale System.out.println("Locale1:" + locale); // print the country of this locale System.out.println("Country:" + locale.getCountry()); } }
輸出
讓我們編譯並執行上述程式,這將產生以下結果:
Locale1:en_US Country:US
從 Canada 區域設定獲取國家示例
以下示例演示了 Java Locale getCountry() 方法的使用。我們正在建立一個 Canada 區域設定,然後檢索並列印其國家/地區。
package com.tutorialspoint; import java.util.Locale; public class LocaleDemo { public static void main(String[] args) { // create a new locale Locale locale = Locale.CANADA; // print this locale System.out.println("Locale1:" + locale); // print the country of this locale System.out.println("Country:" + locale.getCountry()); } }
輸出
讓我們編譯並執行上述程式,這將產生以下結果:
Locale1:en_CA Country:CA
從 FRANCE 區域設定獲取國家示例
以下示例演示了 Java Locale getCountry() 方法的使用。我們正在建立一個 France 區域設定,然後檢索並列印其國家/地區。
package com.tutorialspoint; import java.util.Locale; public class LocaleDemo { public static void main(String[] args) { // create a new locale Locale locale = Locale.FRANCE; // print this locale System.out.println("Locale1:" + locale); // print the country of this locale System.out.println("Country:" + locale.getCountry()); } }
輸出
讓我們編譯並執行上述程式,這將產生以下結果:
Locale1:fr_FR Country:FR
java_util_locale.htm
廣告