The java.util.Locale class represents a locale.
There are three main components of a Locale object:
- language,
- country, and
- variant.
The variant argument is a vendor- or browser-specific code.
For example, you use WIN for Windows, MAC for Macintosh, and POSIX for POSIX.
If there are two variants, separate them with an underscore, and put the most important one first.
To construct a Locale object, use one of the Locale class's constructors.
public Locale(java.lang.String language)
public Locale(java.lang.String language, java.lang.String country)
public Locale(java.lang.String language, java.lang.String country, java.lang.String variant)
To construct a Locale object representing the English language used in Canada.
Locale locale = new Locale ("en", "CA");
You can also construct a Locale object by calling its static field:
Locale locale = Locale. CANADA_FRENCH;
The static getDefault method returns the user computer's locale.
Locale locale = Locale.getDefault ();