Java.util.Locale.getDisplayName() 方法



描述

java.util.Locale.getDisplayName(Locale inLocale) 方法返回適合顯示給使用者的區域設定名稱。這將是 getDisplayLanguage()、getDisplayCountry() 和 getDisplayVariant() 返回的值組合成單個字串。

宣告

以下是 java.util.Locale.getDisplayName() 方法的宣告

public String getDisplayName(Locale inLocale)

引數

返回值

此方法不返回值。

異常

NullPointerException − 如果 inLocale 為空

示例

以下示例顯示了 java.util.Locale.getDisplayName() 方法的用法。

package com.tutorialspoint;

import java.util.*;

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

      // create a new locale
      Locale locale = new Locale("ENGLISH", "US");

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

      // print display name for locale - based on inLocale
      System.out.println("Name:"
         + locale.getDisplayName(new Locale("GERMAN", "GERMANY")));
   }
}

讓我們編譯並執行上述程式,這將產生以下結果:

Locale:english_US
Name:english (United States)
java_util_locale.htm
廣告
© . All rights reserved.