Locale.Builder setRegion() method in Java with Examples
The setRegion(String) method of java.util.Locale.Builder class in Java is used to set this Locale.Builder to the specified region. It means that this method will set the current region of Locale.Builder instance to match the provided region and return it. If the specified region is null or empty, then the region of this LocaleBuilder is removed. A well-formed region value comprises of a 2-letter region code as defined by the ISO 3166 standard or a 3-digit UN M.49 area code.
public Locale.Builder setRegion(String region)
Parameter: This method accepts the region as a parameter which is the String that is to be set to this Locale.Builder instance.
Return Value: This method returns an Locale.Builder instance with the region set of this Locale.Builder to the specified region.
Exception: This method throws following Exceptions:
- IllformedLocaleException: if the specified region has any ill formed fields
LocaleBuilder: java.util.Locale$Builder@232204a1 Setting the region: IN Updated LocaleBuilder: java.util.Locale$Builder@232204a1
LocaleBuilder: java.util.Locale$Builder@232204a1 Setting the region: asdasf@!vsd# java.util.IllformedLocaleException: Ill-formed region: asdasf@!vsd# [at index 0]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.