當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java Locale getVariant()用法及代碼示例


Java中的Locale類的getVariant()方法用於獲取指定語言環境的變體代碼。如果未指定任何內容,則返回一個空字符串

用法:

LOCALE.getLanguage()

參數:此方法不帶任何參數。


返回值:此方法返回空字符串或給定語言環境的變體代碼。

以下示例程序旨在說明getVariant()方法的用法:

示例1:

// Java code to illustrate getVariant() method 
  
import java.util.*; 
  
public class Locale_Demo { 
    public static void main(String[] args) 
    { 
  
        // Creating a new locale 
        Locale first_locale 
            = new Locale("nu", "NO", "NY"); 
  
        // Displaying first locale 
        System.out.println("First Locale: "
                           + first_locale); 
  
        // Displaying the variant_code of this locale 
        System.out.println("Variant: "
                           + first_locale.getVariant()); 
    } 
}
輸出:
First Locale: nu_NO_NY
Variant: NY

示例2:

// Java code to illustrate getVariant() 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 variant_code of this locale 
        System.out.println("Variant: "
                           + first_locale.getVariant()); 
    } 
}
輸出:
First Locale: ar_SA
Variant:


相關用法


注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 Locale getVariant() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。