Java的Locale getISO3Language() 方法和示例
Java中Locale 类的getISO3Language()方法用于获取 locale 中指定语言的三个字母缩写。如果语言环境未指定语言,这将是小写的 ISO 639-2/T 语言代码或空字符串。
句法:
LOCALE.getISO3Language()
参数:该方法不带任何参数。
返回值:此方法不返回任何值。
异常:如果三字母语言缩写对于指定的语言环境不可用,则该方法将引发MissingResourceException 。
下面的程序说明了 getISO3Language() 方法的工作:
方案一:
// 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
方案二:
// 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