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


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


Java語言環境類的getISO3Language()方法用於獲取語言環境中指定的語言的三個字母的縮寫。這將是小寫的ISO 639-2 /T語言代碼,或者在語言環境未指定語言的情況下為空字符串。

用法:

LOCALE.getISO3Language()

參數:此方法不帶任何參數。


返回值:此方法不返回任何值。

異常:如果三個字母的語言縮寫不適用於指定的語言環境,則該方法將引發MissingResourceException。

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

程序1:

// Java code to illustrate getISO3Language() 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_code of this locale 
        System.out.println("Language: "
                           + first_locale.getISO3Language()); 
    } 
}
輸出:
First Locale: en_IN
Language: eng

程序2:

// Java code to illustrate getISO3Language() 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_code of this locale 
        System.out.println("Language: "
                           + first_locale.getISO3Language()); 
    } 
}
輸出:
First Locale: ar_SA
Language: ara

程序3:顯示錯誤

// Java code to illustrate getISO3Language() method 
import java.util.*; 
  
public class Locale_Demo { 
    public static void main(String[] args) 
    { 
  
        // Creating a new locale 
        Locale first_locale 
            = new Locale("engh", "US"); 
  
        // Displaying first locale 
        System.out.println("First Locale: "
                           + first_locale); 
  
        try { 
            // Displaying the language_code of this locale 
            System.out.println("Language: "
                               + first_locale.getISO3Language()); 
        } 
        catch (Exception e) { 
            System.out.println(e); 
        } 
    } 
}
輸出:
First Locale: engh_US
java.util.MissingResourceException: Couldn't find 3-letter language code for engh


相關用法


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