getISO3Country(): This method is available in java.util.Locale class of Java.
Syntax:
String java.util.Locale.getISO3Country() throws MissingResourceException
This method returns a three-letter abbreviation for this locale's country. If the country matches an ISO 3166-1 alpha-2 code, the corresponding ISO 3166-1 alpha-3 uppercase code is returned.
Note: If the locale doesn't specify a country, this will be the empty string.
Returns: A three-letter abbreviation of this locale's country.
Throws: MissingResourceException - if the three-letter country abbreviation is not available for this locale.
For Example:
Locale locale = new Locale("en", "IN")
locale.getISO3Country() = > It returns IND.
Approach 1: When 3-letter code is found.
Java
import java.util.Locale;public class LocalegetISO3Country {public static void main(String[] args) {Locale locale = new Locale("en", "IN");System.out.println(locale.getISO3Country());}}
Output:
IND
Approach 2: When 3 -letter code is not found.
Java
import java.util.Locale;public class LocalegetISO3Country {public static void main(String[] args) {Locale locale = new Locale("en", "USA");System.out.println(locale.getISO3Country());}}
Output:
Exception in thread "main" java.util.MissingResourceException:Couldn't find 3-letter country code for USA at java.base/java.util.Locale.getISO3Country(Locale.java:1774)
No comments:
Post a Comment