Java Utility Library

Java.util.Locale Class



Java Locale Class

Java.util package provides a Locale class. A Locale object represents a specific geographical, political, or cultural region. An operation that requires a Locale to perform its task is called locale-sensitive and uses the Locale to tailor information for the user. For example, displaying a number is a locale-sensitive operation— the number should be formatted according to the customs and conventions of the user's native country, region, or culture. The locale is just a mechanism for identifying objects, not a container for the objects themselves.

Class declaration

The declaration of java.util.Locale class is:

public final class Locale
  extends Object
    implements Cloneable, Serializable

Fields

S.NField and Description
1. static Locale CANADA
Useful constant for country.
2. static Locale CANADA_FRENCH
Useful constant for country.
3. static Locale CHINA
Useful constant for country.
4. static Locale CHINESE
Useful constant for language.
5. static Locale ENGLISH
Useful constant for language.
6. static Locale FRANCE
Useful constant for country.
7. static Locale FRENCH
Useful constant for language.
8. static Locale GERMAN
Useful constant for language.
9. static Locale GERMANY
Useful constant for country.
10. static Locale ITALIAN
Useful constant for language.
11. static Locale ITALY
Useful constant for country.
12. static Locale JAPAN
Useful constant for country.
13. static Locale JAPANESE
Useful constant for language.
14. static Locale KOREA
Useful constant for country.
15. static Locale KOREAN
Useful constant for language.
16. static Locale PRC
Useful constant for country.
17. static char PRIVATE_USE_EXTENSION
The key for the private use extension ('x').
18. static Locale ROOT
Useful constant for the root locale.
19. static Locale SIMPLIFIED_CHINESE
Useful constant for language.
20. static Locale TAIWAN
Useful constant for country.
21. static Locale TRADITIONAL_CHINESE
Useful constant for language.
22. static Locale UK
Useful constant for country.
23. static char UNICODE_LOCALE_EXTENSION
The key for Unicode locale extension ('u').
24. static Locale US
Useful constant for country.

Class Constructors

S.NConstructors & Description
1. Locale(String language)
Construct a locale from a language code.
2. Locale(String language, String country)
Construct a locale from language and country.
3. Locale(String language, String country, String variant)
Construct a locale from language, country and variant.

java.util.Locale Methods

The java.util.Locale class has a number of methods which are listed below:

Member Methods

S.NMethods & Description
1. Object clone()
Overrides Cloneable.
2. boolean equals(Object obj)
Returns true if this Locale is equal to another object.
3. String getDisplayCountry()
Returns a name for the locale's country that is appropriate for display to the user.
4. String getDisplayCountry(Locale inLocale)
Returns a name for the locale's country that is appropriate for display to the user.
5. String getDisplayLanguage()
Returns a name for the locale's language that is appropriate for display to the user.
6. String getDisplayLanguage(Locale inLocale)
Returns a name for the locale's language that is appropriate for display to the user.
7. String getDisplayName()
Returns a name for the locale that is appropriate for display to the user.
8. String getDisplayName(Locale inLocale)
Returns a name for the locale that is appropriate for display to the user.
9. String getDisplayScript()
Returns a name for the locale's script that is appropriate for display to the user.
10. String getDisplayScript(Locale inLocale)
Returns a name for the locale's script that is appropriate for display to the user.
11. String getDisplayVariant()
Returns a name for the locale's variant code that is appropriate for display to the user.
12. String getDisplayVariant(Locale inLocale)
Returns a name for the locale's variant code that is appropriate for display to the user.
13. String getISO3Country()
Returns a three-letter abbreviation for this locale's country.
14. String getISO3Language()
Returns a three-letter abbreviation of this locale's language.
15. String getLanguage()
Returns the language code of this Locale.
16. String getScript()
Returns the script for this locale, which should either be the empty string or an ISO 15924 4-letter script code.
17. String getVariant()
Returns the variant code for this locale.
18. boolean hasExtensions()
Returns true if this Locale has any extensions.
19. int hashCode()
Override hashCode.
20. String toLanguageTag()
Returns a well-formed IETF BCP 47 language tag representing this locale.
21. String toString()
Returns a string representation of this Locale object, consisting of language, country, variant, script, and extensions as below: language + "_" + country + "_" + (variant + "_#" | "#") + script + "-" + extensions Language is always lower case, country is always upper case, script is always title case, and extensions are always lower case.

Methods inherited

This class inherits the methods of following class:

  • java.lang.Object