Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Java.io.PrintWriter class in Java | Set 2
Next article icon

Java.util.Locale Class in Java | Set 2

Last Updated : 28 Jun, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

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 : -----------

  1.  
  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 : ---- 

  1.  
  2. getISO3Language() : java.util.Locale.getISO3Language() displays 3-letter abbreviation of Locale Language. 
    Syntax : 
public String getISO3Language() Parameters :  ---- Return : -------------

  1.  
  2. getISOLanguages() : java.util.Locale.getISOLanguages() displays 2-letter abbreviation list of language as per ISO 639 
    Syntax : 
public static String[] getISOLanguages() Parameters :  ---- Return : -------------

  1.  
  2. getISOCountries() : java.util.Locale.getISOCountries() displays 2-letter abbreviation list of Countries as per ISO 3166. 
    Syntax : 
public static String[] getISOCountries() Parameters :  ---- Return : -------------

  1.  
  2. getVariant() : java.util.Locale.getVariant() returns variant code for the Locale. 
    Syntax : 
public String getVariant() Parameters :  ---- Return : -------------

  1.  
  2. 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 : -------------

  1.  
  2. hashCode() : java.util.Locale.hashCode() returns hashcode for the Locale 
    Syntax : 
public int hashCode() Parameters :  ---- Return : hashcode for the Locale.

  1.  
  2. toString() : java.util.Locale.toString() returns string representation of the entire Locale. 
    Syntax : 
public final String toString() Parameters :  ---- Return : string representation of Locale

  1.  
  2. 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

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

 


Next Article
Java.io.PrintWriter class in Java | Set 2

M

Mohit Gupta_OMG
Improve
Article Tags :
  • Java
  • Java - util package
Practice Tags :
  • Java

Similar Reads

  • Java.util.Locale Class in Java | Set 1
    As the name suggests util.Locale Class is used to perform locale tasks and provides locale information for the user. Declaration : public final class Locale extends Object implements Cloneable, Serializable Constructors : Locale(String L): Creates Locale from the given language code.Locale(String L,
    4 min read
  • java.time.LocalDate Class in Java
    Java is the most popular programming language and widely used programming language. Java is used in all kind of application like as mobile application, desktop application, web application. In this Java java.time.LocalDate class is imported which represents to display the current date. java.time: It
    4 min read
  • java.time.LocalDateTime Class in Java
    java.time.LocalDateTime class, introduced in Java 8, represents a local date-time object without timezone information. The LocalDateTime class in Java is an immutable date-time object that represents a date in the yyyy-MM-dd-HH-mm-ss.zzz format. It implements the ChronoLocalDateTime interface and in
    4 min read
  • Java.io.Printstream Class in Java | Set 2
    Java.io.Printstream Class in Java | Set 1More Methods: PrintStream printf(Locale l, String format, Object... args) : A convenience method to write a formatted string to this output stream using the specified format string and arguments. Syntax :public PrintStream printf(Locale l, String format, Obje
    6 min read
  • Java.io.PrintWriter class in Java | Set 2
    Java.io.PrintWriter class in Java | Set 1 More methods: PrintWriter printf(Locale l, String format, Object... args) : A convenience method to write a formatted string to this writer using the specified format string and arguments. Syntax :public PrintWriter printf(Locale l, String format, Object...
    7 min read
  • Java.util Package in Java
    Java.util PackageIt contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array).Following are the Important Classes in Java.util package
    4 min read
  • Java.lang.ThreadLocal Class in Java
    This class provides thread-local variables. These variables differ from their normal counterparts in that each thread that accesses one (via its get or set method) has its own, independently initialized copy of the variable. Basically, it is another way to achieve thread safety apart from writing im
    4 min read
  • Java.lang.Character.Subset Class in Java
    Character.Subset Class represents particular subsets of the Unicode(standards using hexadecimal values to express characters - 16bit) character set. The subset, it defines in Character set is UnicodeBlock. Declaration : public static class Character.Subset extends Object Constructors : protected Cha
    2 min read
  • Java.Lang.Double Class in Java
    Double class is a wrapper class for the primitive type double which contains several methods to effectively deal with a double value like converting it to a string representation, and vice-versa. An object of the Double class can hold a single double value. Double class is a wrapper class for the pr
    4 min read
  • Java.lang.Character.UnicodeBlock Class in Java
    Character.UnicodeBlock Class represents particular Character blocks of the Unicode(standards using hexadecimal values to express characters - 16 bit) specifications. Character Blocks define characters used for specific purpose. Declaration : public static final class Character.UnicodeBlock extends C
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences