Java中的Locale类的getCountry()方法用于获取指定语言环境的国家或地区代码。这将是一个空字符串或一个大写的ISO 3166 2字母代码或一个UN M.49 3位数代码。
用法:
LOCALE.getCountry()
参数:此方法不带任何参数。
返回值:此方法返回给定语言环境的国家或地区代码;如果语言环境为空,则返回一个空字符串。
以下示例程序旨在说明getCountry()方法的用法:
示例1:
// Java code to illustrate getCountry() method
import java.util.*;
public class Locale_Demo {
public static void main(String[] args)
{
// Creating a new locale
Locale first_locale
= new Locale("English", "UK");
// Displaying first locale
System.out.println("First Locale: "
+ first_locale);
// Displaying the country_code of this locale
System.out.println("Country: "
+ first_locale.getCountry());
}
}
输出:
First Locale: english_UK
Country: UK
示例2:
// Java code to illustrate getCountry() method
import java.util.*;
public class Locale_Demo {
public static void main(String[] args)
{
// Creating a new locale
Locale first_locale
= new Locale("English", "India");
// Displaying first locale
System.out.println("First Locale: "
+ first_locale);
// Displaying the country_code of this locale
System.out.println("Country: "
+ first_locale.getCountry());
}
}
输出:
First Locale: english_INDIA
Country: INDIA