GeezerVison is showing docs.oracle.com — Locale (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
compact1, compact2, compact3
java.util
Class Locale
-
-
Nested Class Summary
Nested Classes
| Modifier and Type |
Class |
Description |
static class |
Locale.Builder |
Builder is used to build instances of Locale
from values configured by the setters.
|
static class |
Locale.Category |
Enum for locale categories.
|
static class |
Locale.FilteringMode |
This enum provides constants to select a filtering mode for locale
matching.
|
static class |
Locale.LanguageRange |
|
-
Constructor Summary
Constructors
| Constructor |
Description |
Locale(String language) |
Construct a locale from a language code.
|
Locale(String language,
String country) |
Construct a locale from language and country.
|
Locale(String language,
String country,
String variant) |
Construct a locale from language, country and variant.
|
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods
| Modifier and Type |
Method |
Description |
Object |
clone() |
Overrides Cloneable.
|
boolean |
equals(Object obj) |
Returns true if this Locale is equal to another object.
|
static List<Locale> |
filter(List<Locale.LanguageRange> priorityList,
Collection<Locale> locales) |
Returns a list of matching Locale instances using the filtering
mechanism defined in RFC 4647.
|
static List<Locale> |
filter(List<Locale.LanguageRange> priorityList,
Collection<Locale> locales,
Locale.FilteringMode mode) |
Returns a list of matching Locale instances using the filtering
mechanism defined in RFC 4647.
|
static List<String> |
filterTags(List<Locale.LanguageRange> priorityList,
Collection<String> tags) |
Returns a list of matching languages tags using the basic filtering
mechanism defined in RFC 4647.
|
static List<String> |
filterTags(List<Locale.LanguageRange> priorityList,
Collection<String> tags,
Locale.FilteringMode mode) |
Returns a list of matching languages tags using the basic filtering
mechanism defined in RFC 4647.
|
static Locale |
forLanguageTag(String languageTag) |
Returns a locale for the specified IETF BCP 47 language tag string.
|
static Locale[] |
getAvailableLocales() |
Returns an array of all installed locales.
|
String |
getCountry() |
Returns the country/region code for this locale, which should
either be the empty string, an uppercase ISO 3166 2-letter code,
or a UN M.49 3-digit code.
|
static Locale |
getDefault() |
Gets the current value of the default locale for this instance
of the Java Virtual Machine.
|
static Locale |
getDefault(Locale.Category category) |
Gets the current value of the default locale for the specified Category
for this instance of the Java Virtual Machine.
|
String |
getDisplayCountry() |
Returns a name for the locale's country that is appropriate for display to the
user.
|
String |
getDisplayCountry(Locale inLocale) |
Returns a name for the locale's country that is appropriate for display to the
user.
|
String |
getDisplayLanguage() |
Returns a name for the locale's language that is appropriate for display to the
user.
|
String |
getDisplayLanguage(Locale inLocale) |
Returns a name for the locale's language that is appropriate for display to the
user.
|
String |
getDisplayName() |
Returns a name for the locale that is appropriate for display to the
user.
|
String |
getDisplayName(Locale inLocale) |
Returns a name for the locale that is appropriate for display
to the user.
|
String |
getDisplayScript() |
Returns a name for the the locale's script that is appropriate for display to
the user.
|
String |
getDisplayScript(Locale inLocale) |
Returns a name for the locale's script that is appropriate
for display to the user.
|
String |
getDisplayVariant() |
Returns a name for the locale's variant code that is appropriate for display to the
user.
|
String |
getDisplayVariant(Locale inLocale) |
Returns a name for the locale's variant code that is appropriate for display to the
user.
|
String |
getExtension(char key) |
Returns the extension (or private use) value associated with
the specified key, or null if there is no extension
associated with the key.
|
Set<Character> |
getExtensionKeys() |
Returns the set of extension keys associated with this locale, or the
empty set if it has no extensions.
|
String |
getISO3Country() |
Returns a three-letter abbreviation for this locale's country.
|
String |
getISO3Language() |
Returns a three-letter abbreviation of this locale's language.
|
static String[] |
getISOCountries() |
Returns a list of all 2-letter country codes defined in ISO 3166.
|
static String[] |
getISOLanguages() |
Returns a list of all 2-letter language codes defined in ISO 639.
|
String |
getLanguage() |
Returns the language code of this Locale.
|
String |
getScript() |
Returns the script for this locale, which should
either be the empty string or an ISO 15924 4-letter script
code.
|
Set<String> |
getUnicodeLocaleAttributes() |
Returns the set of unicode locale attributes associated with
this locale, or the empty set if it has no attributes.
|
Set<String> |
getUnicodeLocaleKeys() |
Returns the set of Unicode locale keys defined by this locale, or the empty set if
this locale has none.
|
String |
getUnicodeLocaleType(String key) |
Returns the Unicode locale type associated with the specified Unicode locale key
for this locale.
|
String |
getVariant() |
Returns the variant code for this locale.
|
boolean |
hasExtensions() |
|
int |
hashCode() |
Override hashCode.
|
static Locale |
lookup(List<Locale.LanguageRange> priorityList,
Collection<Locale> locales) |
Returns a Locale instance for the best-matching language
tag using the lookup mechanism defined in RFC 4647.
|
static String |
lookupTag(List<Locale.LanguageRange> priorityList,
Collection<String> tags) |
Returns the best-matching language tag using the lookup mechanism
defined in RFC 4647.
|
static void |
setDefault(Locale.Category category,
Locale newLocale) |
Sets the default locale for the specified Category for this instance
of the Java Virtual Machine.
|
static void |
setDefault(Locale newLocale) |
Sets the default locale for this instance of the Java Virtual Machine.
|
Locale |
stripExtensions() |
|
String |
toLanguageTag() |
Returns a well-formed IETF BCP 47 language tag representing
this locale.
|
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.
|
-
-
Field Detail
-
ROOT
public static final Locale ROOT
Useful constant for the root locale. The root locale is the locale whose
language, country, and variant are empty ("") strings. This is regarded
as the base locale of all locales, and is used as the language/country
neutral locale for the locale sensitive operations.
- Since:
- 1.6
-
Method Detail
-
getScript
public String getScript()
Returns the script for this locale, which should
either be the empty string or an ISO 15924 4-letter script
code. The first letter is uppercase and the rest are
lowercase, for example, 'Latn', 'Cyrl'.
- Returns:
- The script code, or the empty string if none is defined.
- Since:
- 1.7
- See Also:
getDisplayScript()
-
getCountry
public String getCountry()
Returns the country/region code for this locale, which should
either be the empty string, an uppercase ISO 3166 2-letter code,
or a UN M.49 3-digit code.
- Returns:
- The country/region code, or the empty string if none is defined.
- See Also:
getDisplayCountry()
-
getExtension
public String getExtension(char key)
Returns the extension (or private use) value associated with
the specified key, or null if there is no extension
associated with the key. To be well-formed, the key must be one
of [0-9A-Za-z]. Keys are case-insensitive, so
for example 'z' and 'Z' represent the same extension.
- Parameters:
key - the extension key
- Returns:
- The extension, or null if this locale defines no
extension for the specified key.
- Throws:
IllegalArgumentException - if key is not well-formed
- Since:
- 1.7
- See Also:
PRIVATE_USE_EXTENSION,
UNICODE_LOCALE_EXTENSION
-
getExtensionKeys
public Set<Character> getExtensionKeys()
Returns the set of extension keys associated with this locale, or the
empty set if it has no extensions. The returned set is unmodifiable.
The keys will all be lower-case.
- Returns:
- The set of extension keys, or the empty set if this locale has
no extensions.
- Since:
- 1.7
-
getUnicodeLocaleAttributes
public Set<String> getUnicodeLocaleAttributes()
Returns the set of unicode locale attributes associated with
this locale, or the empty set if it has no attributes. The
returned set is unmodifiable.
- Returns:
- The set of attributes.
- Since:
- 1.7
-
getUnicodeLocaleType
public String getUnicodeLocaleType(String key)
Returns the Unicode locale type associated with the specified Unicode locale key
for this locale. Returns the empty string for keys that are defined with no type.
Returns null if the key is not defined. Keys are case-insensitive. The key must
be two alphanumeric characters ([0-9a-zA-Z]), or an IllegalArgumentException is
thrown.
- Parameters:
key - the Unicode locale key
- Returns:
- The Unicode locale type associated with the key, or null if the
locale does not define the key.
- Throws:
IllegalArgumentException - if the key is not well-formed
NullPointerException - if key is null
- Since:
- 1.7
-
getUnicodeLocaleKeys
public Set<String> getUnicodeLocaleKeys()
Returns the set of Unicode locale keys defined by this locale, or the empty set if
this locale has none. The returned set is immutable. Keys are all lower case.
- Returns:
- The set of Unicode locale keys, or the empty set if this locale has
no Unicode locale keywords.
- Since:
- 1.7
-
getISO3Language
public String getISO3Language()
throws MissingResourceException
Returns a three-letter abbreviation of this locale's language.
If the language matches an ISO 639-1 two-letter code, the
corresponding ISO 639-2/T three-letter lowercase code is
returned. The ISO 639-2 language codes can be found on-line,
see "Codes for the Representation of Names of Languages Part 2:
Alpha-3 Code". If the locale specifies a three-letter
language, the language is returned as is. If the locale does
not specify a language the empty string is returned.
- Returns:
- A three-letter abbreviation of this locale's language.
- Throws:
MissingResourceException - Throws MissingResourceException if
three-letter language abbreviation is not available for this locale.
-
getDisplayLanguage
public String getDisplayLanguage(Locale inLocale)
Returns a name for the locale's language that is appropriate for display to the
user.
If possible, the name returned will be localized according to inLocale.
For example, if the locale is fr_FR and inLocale
is en_US, getDisplayLanguage() will return "French"; if the locale is en_US and
inLocale is fr_FR, getDisplayLanguage() will return "anglais".
If the name returned cannot be localized according to inLocale,
(say, we don't have a Japanese name for Croatian),
this function falls back on the English name, and finally
on the ISO code as a last-resort value. If the locale doesn't specify a language,
this function returns the empty string.
- Parameters:
inLocale - The locale for which to retrieve the display language.
- Returns:
- The name of the display language appropriate to the given locale.
- Throws:
NullPointerException - if inLocale is null
-
getDisplayScript
public String getDisplayScript(Locale inLocale)
Returns a name for the locale's script that is appropriate
for display to the user. If possible, the name will be
localized for the given locale. Returns the empty string if
this locale doesn't specify a script code.
- Parameters:
inLocale - The locale for which to retrieve the display script.
- Returns:
- the display name of the script code for the current default
DISPLAY locale
- Throws:
NullPointerException - if inLocale is null
- Since:
- 1.7
-
getDisplayCountry
public String getDisplayCountry(Locale inLocale)
Returns a name for the locale's country that is appropriate for display to the
user.
If possible, the name returned will be localized according to inLocale.
For example, if the locale is fr_FR and inLocale
is en_US, getDisplayCountry() will return "France"; if the locale is en_US and
inLocale is fr_FR, getDisplayCountry() will return "Etats-Unis".
If the name returned cannot be localized according to inLocale.
(say, we don't have a Japanese name for Croatia),
this function falls back on the English name, and finally
on the ISO code as a last-resort value. If the locale doesn't specify a country,
this function returns the empty string.
- Parameters:
inLocale - The locale for which to retrieve the display country.
- Returns:
- The name of the country appropriate to the given locale.
- Throws:
NullPointerException - if inLocale is null
-
getDisplayVariant
public String getDisplayVariant(Locale inLocale)
Returns a name for the locale's variant code that is appropriate for display to the
user. If possible, the name will be localized for inLocale. If the locale
doesn't specify a variant code, this function returns the empty string.
- Parameters:
inLocale - The locale for which to retrieve the display variant code.
- Returns:
- The name of the display variant code appropriate to the given locale.
- Throws:
NullPointerException - if inLocale is null
-
clone
public Object clone()
Overrides Cloneable.
- Overrides:
clone in class Object
- Returns:
- a clone of this instance.
- See Also:
Cloneable
-
equals
public boolean equals(Object obj)
Returns true if this Locale is equal to another object. A Locale is
deemed equal to another Locale with identical language, script, country,
variant and extensions, and unequal to all other objects.
- Overrides:
equals in class Object
- Parameters:
obj - the reference object with which to compare.
- Returns:
- true if this Locale is equal to the specified object.
- See Also:
Object.hashCode(),
HashMap
-
filter
public static List<Locale> filter(List<Locale.LanguageRange> priorityList,
Collection<Locale> locales,
Locale.FilteringMode mode)
Returns a list of matching Locale instances using the filtering
mechanism defined in RFC 4647.
- Parameters:
priorityList - user's Language Priority List in which each language
tag is sorted in descending order based on priority or weight
locales - Locale instances used for matching
mode - filtering mode
- Returns:
- a list of
Locale instances for matching language tags
sorted in descending order based on priority or weight, or an empty
list if nothing matches. The list is modifiable.
- Throws:
NullPointerException - if priorityList or locales
is null
IllegalArgumentException - if one or more extended language ranges
are included in the given list when
Locale.FilteringMode.REJECT_EXTENDED_RANGES is specified
- Since:
- 1.8
-
filterTags
public static List<String> filterTags(List<Locale.LanguageRange> priorityList,
Collection<String> tags,
Locale.FilteringMode mode)
Returns a list of matching languages tags using the basic filtering
mechanism defined in RFC 4647.
- Parameters:
priorityList - user's Language Priority List in which each language
tag is sorted in descending order based on priority or weight
tags - language tags
mode - filtering mode
- Returns:
- a list of matching language tags sorted in descending order
based on priority or weight, or an empty list if nothing matches.
The list is modifiable.
- Throws:
NullPointerException - if priorityList or tags is
null
IllegalArgumentException - if one or more extended language ranges
are included in the given list when
Locale.FilteringMode.REJECT_EXTENDED_RANGES is specified
- Since:
- 1.8
-
lookup
public static Locale lookup(List<Locale.LanguageRange> priorityList,
Collection<Locale> locales)
Returns a Locale instance for the best-matching language
tag using the lookup mechanism defined in RFC 4647.
- Parameters:
priorityList - user's Language Priority List in which each language
tag is sorted in descending order based on priority or weight
locales - Locale instances used for matching
- Returns:
- the best matching
Locale instance chosen based on
priority or weight, or null if nothing matches.
- Throws:
NullPointerException - if priorityList or tags is
null
- Since:
- 1.8
-
lookupTag
public static String lookupTag(List<Locale.LanguageRange> priorityList,
Collection<String> tags)
Returns the best-matching language tag using the lookup mechanism
defined in RFC 4647.
- Parameters:
priorityList - user's Language Priority List in which each language
tag is sorted in descending order based on priority or weight
tags - language tangs used for matching
- Returns:
- the best matching language tag chosen based on priority or
weight, or
null if nothing matches.
- Throws:
NullPointerException - if priorityList or tags is
null
- Since:
- 1.8
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|