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


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。