Java Locale getCountry() Example
Locale class getCountry() method example. This example shows you how to use getCountry() method.
Syntax is : public public String getCountry()
Method returns the country/region code for this locale, which will either be the empty string or an uppercase ISO 3166 2-letter code.
Here is the code.
/**
* @(#) GetCountryLocale.java
* A class representing use of method getCountry() of Locale class
in java.util Package.
* @Version 24-May-2008
* @author Rose India Team
*/
import java.util.*;
class GetCountryLocale {
public static void main( String args[] ){
/* Create object of Locale class using contructor
Locale(String language, String country) */
Locale obj1 = new Locale("ENGLISH","Us");
Locale obj2 = new Locale("CHIENESE","China");
System.out.println("object obj1 of Locale class is : "+obj1);
System.out.println("object obj2 of Locale class is : "+obj2);
// getCountry() method call.
String country = obj1.getCountry();
System.out.println("Country code for object obj1 : " + country);
country = obj2.getCountry();
System.out.println("Country code for object obj2 : " + country);
}
} |
Output of the program.
object objLocale1 of Locale class is : english_US
object objLocale2 of Locale class is : chienese_CHINA
Country code for object obj1 : US
Country code for object obj2 : CHINA |
|