当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Locale getDisplayCountry(Locale)用法及代码示例


Java中Locale类的getDisplayCountry(Locale inLoc)方法用于获取指定语言环境的国家或地区名称。该名称将根据inLoc进行本地化。

用法:

public String getDisplayCountry(Locale inLoc)

参数:此方法采用Locale类型的inLoc参数,该参数表示名称的本地化显示。


返回值:此方法返回适合给定语言环境和用户的国家名称。

异常:如果参数inLoc为null,则该方法引发NullPointerException。

以下示例程序旨在说明getDisplayCountry()方法的用法:
示例1:

// Java code to illustrate getDisplayCountry() method 
  
import java.util.*; 
  
public class Locale_Demo { 
    public static void main(String[] args) 
    { 
  
        // Creating a new locale 
        Locale first_locale 
            = new Locale("English", "In"); 
  
        // Displaying first locale 
        System.out.println("First Locale: "
                           + first_locale); 
  
        // Displaying the country_name of this locale 
        System.out.println("Country: "
                           + first_locale 
                                 .getDisplayCountry( 
                                     new Locale("Spanish", 
                                                "Spain"))); 
    } 
}
输出:
First Locale: english_IN
Country: India

示例2:

// Java code to illustrate getDisplayCountry() method 
  
import java.util.*; 
  
public class Locale_Demo { 
    public static void main(String[] args) 
    { 
  
        // Creating a new locale 
        Locale first_locale 
            = new Locale("German", "Germany"); 
  
        // Displaying first locale 
        System.out.println("First Locale: "
                           + first_locale); 
  
        // Displaying the country_name of this locale 
        System.out.println("Country: "
                           + first_locale 
                                 .getDisplayCountry( 
                                     new Locale("Eglish", 
                                                "US"))); 
    } 
}
输出:
First Locale: german_GERMANY
Country: GERMANY

参考:https://docs.oracle.com/javase/7/docs/api/java/util/Locale.html#getDisplayCountry(java.util.Locale)



相关用法


注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 Locale getDisplayCountry(Locale) Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。