Java Locale getDisplayCountry() Example
Locale class getDisplayCountry() method example. This example shows you how to use getDisplayCountry() method.
Syntax is : public String getDisplayCountry(Locale inLocale)
Method returns a name for the locale's country and If possible, the name returned will be localized according to inLocale and if the locale
doesn't specify a country, this function returns the empty string.
Here is the code.
/**
* @(#) GetDisplayCountry1Locale.java
* A class representing use of method getDisplayCountry() of Locale class
in java.util Package.
* @Version 24-May-2008
* @author Rose India Team
*/
import java.util.*;
class GetDisplayCountry1Locale {
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","CH");
System.out.println("object obj1 of Locale class is : "+obj1);
System.out.println("object obj2 of Locale class is : "+obj2);
// getDisplayCountry() method call.
String country = obj1.getDisplayCountry(obj2);
System.out.println("Country name for object obj1 : " + country);
country = obj2.getDisplayCountry(obj1);
System.out.println("Country name for object obj2 : " + country);
}
} |
Output of the program.
object objLocale1 of Locale class is : english_US
object objLocale2 of Locale class is : chienese_CH
Country name for object obj1 : United States
Country name for object obj2 : Switzerland |
|