Open In App

Locale getISO3Country() Method in Java with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

The getISO3Country() method of Locale class in Java is used to get the country or region code for the specified locale. This will either be an uppercase ISO 3166 3-letter country code or an empty string if the locale doesn’t specify a country.

Syntax:

LOCALE.getISO3Country()

Parameters: This method does not take any parameters.

Return Value: This method does not return any value.

Exception: The method throws a MissingResourceException if the three-letter country abbreviation is not available for the specified locale.

Below programs illustrate the working of getISO3Country() method:

Program 1:




// Java code to illustrate getISO3Country() method
  
import java.util.*;
  
public class Locale_Demo {
    public static void main(String[] args)
    {
  
        // Creating a new locale
        Locale first_locale
            = new Locale("en", "IN");
  
        // Displaying first locale
        System.out.println("First Locale: "
                           + first_locale);
  
        // Displaying the country_code of this locale
        System.out.println("Country: "
                           + first_locale.getISO3Country());
    }
}


Output:

First Locale: en_IN
Country: IND

Program 2:




// Java code to illustrate getISO3Country() method
import java.util.*;
  
public class Locale_Demo {
    public static void main(String[] args)
    {
  
        // Creating a new locale
        Locale first_locale
            = new Locale("ar", "SA");
  
        // Displaying first locale
        System.out.println("First Locale: "
                           + first_locale);
  
        // Displaying the country_code of this locale
        System.out.println("Country: "
                           + first_locale.getISO3Country());
    }
}


Output:

First Locale: ar_SA
Country: SAU

Program 3: Showing Error




// Java code to illustrate getISO3Country() method
import java.util.*;
  
public class Locale_Demo {
    public static void main(String[] args)
    {
  
        // Creating a new locale
        Locale first_locale
            = new Locale("ar", "tez");
  
        // Displaying first locale
        System.out.println("First Locale: "
                           + first_locale);
  
        try {
            // Displaying the country_code of this locale
            System.out.println("Country: "
                               + first_locale.getISO3Country());
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}


Output:

First Locale: ar_TEZ
java.util.MissingResourceException: Couldn't find 3-letter country code for TEZ


Last Updated : 27 Dec, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads