Java Locale getISO3Country() 方法



描述

java Locale getISO3Country() 方法返回此區域設定的國家/地區的三個字母縮寫。如果區域設定未指定國家/地區,則返回空字串。否則,將返回大寫的 ISO 3166 三字母國家/地區程式碼。

宣告

以下是Java Locale getISO3Country() 方法的宣告

public String getISO3Country()

引數

返回值

此方法不返回值。

異常

MissingResourceException − 如果此區域設定的三個字母國家/地區縮寫不可用,則丟擲 MissingResourceException。

獲取美國區域設定國家/地區的三個字母縮寫示例

以下示例演示了 Java Locale getISO3Country() 方法的用法。我們建立了一個美國的區域設定,然後檢索並列印其國家/地區。

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("Locale:" + locale);

      // print the country of this locale
      System.out.println("Country:" + locale.getISO3Country());
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Locale:en_US
Country:USA

獲取法國區域設定國家/地區的三個字母縮寫示例

以下示例演示了 Java Locale getISO3Country() 方法的用法。我們建立了一個法國的區域設定,然後檢索並列印其國家/地區。

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("Locale:" + locale);

      // print the country of this locale
      System.out.println("Country:" + locale.getISO3Country());
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Locale:fr_FR
Country:FRA

獲取德國區域設定國家/地區的三個字母縮寫示例

以下示例演示了 Java Locale getISO3Country() 方法的用法。我們建立了一個德國的區域設定,然後檢索並列印其國家/地區。

package com.tutorialspoint;

import java.util.Locale;

public class LocaleDemo {
   public static void main(String[] args) {

      // create a new locale
      Locale locale = Locale.GERMANY;

      // print this locale
      System.out.println("Locale:" + locale);

      // print the country of this locale
      System.out.println("Country:" + locale.getISO3Country());
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Locale:de_DE
Country:DEU
java_util_locale.htm
廣告