📌  相关文章
📜  Java的Locale getDisplayLanguage() 方法和示例

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

Java的Locale getDisplayLanguage() 方法和示例

JavaLocale 类getDisplayLanguage()方法用于获取指定语言环境的语言名称。该名称根据用户的方便程度显示。

句法:

LOCALE.getDisplayLanguage()

参数:该方法不带任何参数。

返回值:此方法返回适合给定语言环境的显示语言的名称。

下面的程序说明了 getDisplayLanguage() 方法的工作:



方案一:

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

方案二:

// Java code to illustrate getDisplayLanguage() method
  
import java.util.*;
  
public class Locale_Demo {
    public static void main(String[] args)
    {
  
        // Creating a new locale
        Locale first_locale
            = new Locale("ar", "SA");
  
        // Displaying first locale
        System.out.println("First Locale: "
                           + first_locale);
  
        // Displaying the language of this locale
        System.out.println("Language: "
                           + first_locale.getDisplayLanguage());
    }
}
输出:
First Locale: ar_SA
Language: Arabic