Java.util.Locale Class in Java | Set 2

Java.util.Locale Class in Java | Set 1
More methods:

  1. getDisplayVariant() : java.util.Locale.getDisplayVariant() displays variant of the Locale
    Syntax :
    public final String getDisplayVariant()
    Parameters : 
    ----
    Return :
    -----------
    
  2. getDisplayVariant(Locale in) : java.util.Locale.Locale in(Locale in) returns the variant of “in” locale.
    Syntax :
    public final String getDisplayVariant(Locale in)
    Parameters : 
    in : the instance local
    Return :
    ---- 
    
  3. getISO3Language() : java.util.Locale.getISO3Language() displays 3-letter abbreviation of Locale Language.
    Syntax :
    public String getISO3Language()
    Parameters : 
    ----
    Return :
    -------------
    
  4. getISOLanguages() : java.util.Locale.getISOLanguages() displays 2-letter abbreviation list of language as per ISO 639
    Syntax :
    public static String[] getISOLanguages()
    Parameters : 
    ----
    Return :
    -------------
    
  5. getISOCountries() : java.util.Locale.getISOCountries() displays 2-letter abbreviation list of Countries as per ISO 3166.
    Syntax :
    public static String[] getISOCountries()
    Parameters : 
    ----
    Return :
    -------------
    
  6. getVariant() : java.util.Locale.getVariant() returns variant code for the Locale.
    Syntax :
    public String getVariant()
    Parameters : 
    ----
    Return :
    -------------
    
  7. getLanguage() : java.util.Locale.getLanguage() returns language code for the Locale which will be either empty or as per ISO 639 code in lowercases.
    Syntax :
    public String getLanguage()
    Parameters : 
    ----
    Return :
    -------------
    
  8. hashCode() : java.util.Locale.hashCode() returns hashcode for the Locale
    Syntax :
    public int hashCode()
    Parameters : 
    ----
    Return :
    hashcode for the Locale.
    
  9. toString() : java.util.Locale.toString() returns string representation of the entire Locale.
    Syntax :
    public final String toString()
    Parameters : 
    ----
    Return :
    string representation of Locale
    
  10. setDefault(Locale newLocale) : java.util.Locale.setDefault(Locale newLocale) sets new value for the Locale for the JVM.
    Syntax :
    public static void setDefault(Locale newLocale)
    Parameters : 
    ----
    Return :
    string representation of Locale
    
    // 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);
        }
    }
    

    Output :

    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 represenation for the geek1 : english_IN_IND
    
    Initial Default : en_US
    NEW Default : fr_FRANCE_MAC

This article is contributed by Mohit Gupta_OMG 🙂. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

GATE CS Corner    Company Wise Coding Practice

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.

Recommended Posts:



0 Average Difficulty : 0/5.0
No votes yet.










Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.