當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java Locale getDisplayLanguage(Locale)用法及代碼示例


Java語言環境類的getDisplayLanguage(Locale inLoc)方法用於獲取指定語言環境的語言名稱。如果有可能,返回的名稱將根據inLocale進行本地化。

用法:

public String getDisplayLanguage(Locale inLoc)

參數:此方法采用Locale類型的inLoc參數,該參數表示名稱的本地化顯示。


返回值:此方法返回適合給定語言環境的顯示語言的名稱。

異常:如果參數inLoc為null,則該方法引發NullPointerException。

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

// 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", "US"); 
  
        // Displaying first locale 
        System.out.println("First Locale: "
                           + first_locale); 
  
        // Displaying the language of this locale 
        System.out.println("Language: "
                           + first_locale 
                                 .getDisplayLanguage( 
                                     new Locale("fr", "FR"))); 
    } 
}
輸出:
First Locale: en_US
Language: anglais

示例2:

// 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", "US"); 
  
        // Displaying first locale 
        System.out.println("First Locale: "
                           + first_locale); 
  
        // Displaying the language of this locale 
        System.out.println("Language: "
                           + first_locale 
                                 .getDisplayLanguage( 
                                     new Locale("", "FR"))); 
    } 
}
輸出:
First Locale: en_US
Language: English


相關用法


注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 Locale getDisplayLanguage(Locale) Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。