Class Locale in Java Detailed explanation

A Locale object represents a specific geographical, political, or cultural region. An operation that requires a The 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.

Creating a Locale

There are several different ways to create a Locale object.

  1. Builder: Using Locale. Builder you can construct a Locale object that conforms to BCP 47 syntax.
  2. Constructors: The The locale class provides three constructors:

    Locale(String language) Locale(String language, String country) Locale(String language, String country, String variant)

  3. Factory Methods:

    The method forLanguageTag(java.lang.String) creates a Locale object

Use of Locale

The Java Platform provides several classes that perform locale-sensitive operations. For example, the NumberFormat class formats numbers, currency, and percentages in a locale-sensitive manner.
For example, the NumberFormat class provides these three convenience methods for creating a default NumberFormat object:
NumberFormat.getInstance()
NumberFormat.getCurrencyInstance()
NumberFormat.getPercentInstance()

Each of these methods has two variants; one with an explicit locale and one without; the latter uses the default FORMAT locale:
NumberFormat.getInstance(myLocale)
NumberFormat.getCurrencyInstance(myLocale) NumberFormat.getPercentInstance(myLocale)
A Locale is a mechanism for identifying the kind of object (NumberFormat) that you would like to get. The locale is just a mechanism for identifying objects, not a container for the objects themselves.

Instance Method and Description:
1. clone()
Overrides Cloneable.
2. equals(Object obj)
Returns true if this Locale is equal to another object.
3. forLanguageTag(String languageTag)
Returns a locale for the specified IETF BCP 47 language tag string.
4.getAvailableLocales()
Returns an array of all installed locales.
5.getDefault()
Gets the current value of the default locale for this instance of the Java Virtual Machine.
6.getDisplayCountry(Locale inLocale)
Returns a name for the locale's country that is appropriate for display to the user.
7.getDisplayLanguage() Returns a name for the locale's language that is appropriate for display to the user.
8.getDisplayName(Locale inLocale)
Returns a name for the locale that is appropriate for display to the user.
9.getDisplayScript(Locale inLocale)
Returns a name for the locale's script that is appropriate for display to the user.
10.getDisplayVariant()
Returns a name for the locale's variant code that is appropriate for display to the user.
11.getISO3Country()
Returns a three-letter abbreviation for this locale's country.
12.getISOLanguages()
Returns a list of all 2-letter language codes defined in ISO 639.
13. extensions()
Returns true if this The locale has any extensions
14.stripExtensions()Returns a copy of this The locale with no extensions.