Java Locale getVariant() 方法



描述

Java Locale getVariant() 方法返回此區域設定的變體程式碼。

宣告

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

public String getVariant()

引數

返回值

此方法返回變體程式碼,如果未定義則返回空字串。

異常

從 Locale 獲取變體示例

以下示例演示了 Java Locale getVariant() 方法的使用。我們正在建立美國的區域設定,然後檢索並列印變體程式碼。

package com.tutorialspoint;

import java.util.Locale;

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

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

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

      // print the variant code of this locale
	  System.out.println("Variant Code:" + locale.getVariant());
   }
}

輸出

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

Locale:en_US_WIN
Language:WIN
java_util_locale.htm
廣告

© . All rights reserved.