is used to build instances of
from values configured by the setters. Unlike the
checks if a value configured by a setter satisfies the syntax requirements defined by the
object created by a
is well-formed and can be transformed to a well-formed IETF BCP 47 language tag without losing information.
Locale class does not provide any syntactic restrictions on variant, while BCP 47 requires each variant subtag to be 5 to 8 alphanumerics or a single numeric followed by 3 alphanumerics. The method
IllformedLocaleException for a variant that does not satisfy this restriction. If it is necessary to support such a variant, use a Locale constructor. However, keep in mind that a
Locale object created this way might lose the variant information when transformed to a BCP 47 language tag.
The following example shows how to create a
Locale object with the
Locale aLocale = new Builder().setLanguage("sr").setScript("Latn").setRegion("RS").build();
Builders can be reused;
clear() resets all fields to their default values.