📜  Java.util.Locale 类Java |设置 2

📅  最后修改于: 2022-05-13 01:55:02.550000             🧑  作者: Mango

Java.util.Locale 类Java |设置 2

Java.util.Locale 类Java |设置 1
更多方法:

  1. getDisplayVariant() : Java.util.Locale.getDisplayVariant()显示语言环境的变体
    句法 :
public final String getDisplayVariant()
Parameters : 
----
Return :
-----------
  1. getDisplayVariant(Locale in) : Java.util.Locale.Locale in(Locale in)返回“in”语言环境的变体。
    句法 :
public final String getDisplayVariant(Locale in)
Parameters : 
in : the instance local
Return :
---- 
  1. getISO3Language() : Java.util.Locale.getISO3Language()显示区域设置语言的 3 个字母缩写。
    句法 :
public String getISO3Language()
Parameters : 
----
Return :
-------------
  1. getISOLanguages() : Java.util.Locale.getISOLanguages()根据 ISO 639 显示 2 个字母的语言缩写列表
    句法 :
public static String[] getISOLanguages()
Parameters : 
----
Return :
-------------
  1. getISOCountries() : Java.util.Locale.getISOCountries()根据 ISO 3166 显示国家的 2 个字母缩写列表。
    句法 :
public static String[] getISOCountries()
Parameters : 
----
Return :
-------------
  1. getVariant() : Java.util.Locale.getVariant()返回区域设置的变体代码。
    句法 :
public String getVariant()
Parameters : 
----
Return :
-------------
  1. getLanguage() : Java.util.Locale.getLanguage()返回区域设置的语言代码,该语言代码将为空或按照 ISO 639 小写代码。
    句法 :
public String getLanguage()
Parameters : 
----
Return :
-------------
  1. hashCode() : Java.util.Locale.hashCode()返回区域设置的哈希码
    句法 :
public int hashCode()
Parameters : 
----
Return :
hashcode for the Locale.
  1. toString() : Java.util.Locale.toString()返回整个语言环境的字符串表示。
    句法 :
public final String toString()
Parameters : 
----
Return :
string representation of Locale
  1. setDefault(Locale newLocale) : Java.util.Locale.setDefault(Locale newLocale)为 JVM 的 Locale 设置新值。
    句法 :
public static void setDefault(Locale newLocale)
Parameters : 
----
Return :
string representation of Locale
Java
// Java Program illustrating the use of methods :
// getDisplayVariant(), getDisplayVariant(Locale in),
// getISO3Language(), getISOLanguages(), getVariant(),
// getISOCountries(), getISOLanguages(), hashCode(),
// getLanguage(), toString(), setDefault()
 
import java.util.*;
public class NewClass
{
    public static void main(String[] args)
    {
        // Creating a new Locale
        Locale geek1 = new Locale("English", "IN", "IND");
 
        // Use of getDefault() :
        Locale geek2 = Locale.getDefault();
 
        // Use of getDisplayVariant() :
        System.out.println("\nUse of getDisplayVariant : "
                                + geek1.getDisplayVariant());
 
        // Use of getDisplayVariant(Locale in) :
        System.out.println("Name of in Locale : "
                +geek2.getDisplayVariant(new Locale("English",
                                          "english", "WNN")));
 
        // Use of getISO3Language() :
        System.out.println("Language of geek2 : " +
                                  geek2.getISO3Language());
 
        // Use of getISOLanguages() :
        String[] languages = geek2.getISOLanguages();
 
        // We are not printing the entire list
        System.out.println("\nList of language codes : ");
        for (int i = 1; i < languages.length/20; i++)
            System.out.println(i + ":" + languages[i]);
 
        // Use of getISOCountries() :
        String[] countries = Locale.getISOCountries();
 
        // We are not printing the entire list
        System.out.println("\n Countries of geek2 : ");
        for (int i = 1; i < countries.length/30; i++)
            System.out.println(i + ":" + countries[i]);
 
        // Use of getVariant() :
        System.out.println("\nUse of getVariant : " +
                                    geek1.getVariant());
 
        // Use of getLanguage() :
        System.out.println("Use of getLanguage : " +
                                    geek1.getLanguage());
 
        // Use of hashCode() :
        System.out.println("HashCode for the geek1 : " +
                                       geek1.hashCode());
 
        // Use of toString() :
        System.out.println("String representation for the geek1 : "
                                        + geek1.toString());
 
        // Use of getDefault() :
        Locale geek3 = Locale.getDefault();
        System.out.println("\nInitial Default : " + geek3);
 
        // Use of setDefault() :
        geek3.setDefault(new Locale("fr", "FRANCE", "MAC"));
 
        Locale geek4 = Locale.getDefault();
        System.out.println("NEW Default : " + geek4);
    }
}


  1. 输出 :
Use of getDisplayVariant : IND
Name of in Locale : 
Language of geek2 : eng

List of language codes : 
1:ab
2:ae
3:af
4:ak
5:am
6:an
7:ar
8:as

 Countries of geek2 : 
1:AE
2:AF
3:AG
4:AI
5:AL
6:AM
7:AN

Use of getVariant : IND
Use of getLanguage : english
HashCode for the geek1 : -322025782
String representation for the geek1 : english_IN_IND

Initial Default : en_US
NEW Default : fr_FRANCE_MAC