📌  相关文章
📜  Java中的 Locale getDisplayCountry(Locale) 方法及示例

📅  最后修改于: 2022-05-13 01:55:45.062000             🧑  作者: Mango

Java中的 Locale getDisplayCountry(Locale) 方法及示例

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

句法:

public String getDisplayCountry(Locale inLoc)

参数:该方法接受一个Locale类型的参数inLoc ,表示名称的本地化显示。
返回值:此方法返回适合给定语言环境和用户的国家名称。
异常:如果参数 inLoc 为 null,则该方法抛出NullPointerException
下面的程序说明了 getDisplayCountry() 方法的工作:
示例 1:

Java
// 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")));
    }
}


Java
// 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("English",
                                                "US")));
    }
}


Java
// 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("English",
                                                "US")));
    }
}


输出:
First Locale: english_IN
Country: India

示例 2:

Java

// 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("English",
                                                "US")));
    }
}

Java

// 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("English",
                                                "US")));
    }
}
输出:
First Locale: german_GERMANY
Country: GERMANY

参考: https: Java Java.util.Locale)