Java.util.Locale.getLanguage() 方法



描述

Java Locale getLanguage() 方法返回此区域设置的语言代码,该代码可以是空字符串或小写的 ISO 639 代码。

声明

以下是 Java Locale getLanguage() 方法的声明

public String getLanguage()

参数

返回值

此方法不返回值。

异常

获取美国区域设置语言示例

以下示例演示了 Java Locale getLanguage() 方法的使用。我们创建了一个美国区域设置,然后检索并打印其语言。

package com.tutorialspoint;

import java.util.Locale;

public class LocaleDemo {
   public static void main(String[] args) {

      // create a new locale
      Locale locale = Locale.US;

      // print this locale
      System.out.println("Locale:" + locale);

      // print the language of this locale
      System.out.println("Language:" + locale.getLanguage());
   }
}

输出

让我们编译并运行上述程序,这将产生以下结果:

Locale:en_US
Language:en

获取法国区域设置语言示例

以下示例演示了 Java Locale getLanguage() 方法的使用。我们创建了一个法国区域设置,然后检索并打印其语言。

package com.tutorialspoint;

import java.util.Locale;

public class LocaleDemo {
   public static void main(String[] args) {

      // create a new locale
      Locale locale = Locale.FRANCE;

      // print this locale
      System.out.println("Locale:" + locale);

      // print the language of this locale
      System.out.println("Language:" + locale.getLanguage());
   }
}

输出

让我们编译并运行上述程序,这将产生以下结果:

Locale:fr_FR
Language:fr

获取德国区域设置语言示例

以下示例演示了 Java Locale getLanguage() 方法的使用。我们创建了一个德国区域设置,然后检索并打印其语言。

package com.tutorialspoint;

import java.util.Locale;

public class LocaleDemo {
   public static void main(String[] args) {

      // create a new locale
      Locale locale = Locale.GERMANY;

      // print this locale
      System.out.println("Locale:" + locale);

      // print the language of this locale
      System.out.println("Language:" + locale.getLanguage());
   }
}

输出

让我们编译并运行上述程序,这将产生以下结果:

Locale:de_DE
Language:de
java_util_locale.htm
广告
© . All rights reserved.