Java Locale getDisplayLanguage() Example
Locale class getDisplayName() method example. This example shows you how to use getDisplayName() method.
Syntax is : public String getDisplayName(Locale inLocale)
Method returns a name for the locale that is appropriate for display to the user. This will be the values returned by getDisplayLanguage(),
getDisplayCountry(), and getDisplayVariant() assembled into a single string. If the language, country, and variant fields are all empty,
function returns the empty string.
Here is the code.
/**
* @(#) GetDisplayName1Locale.java
* A class representing use of method getDisplayName() of Locale class
in java.util Package.
* @Version 26-May-2008
* @author Rose India Team
*/
import java.util.*;
class GetDisplayName1Locale {
public static void main( String args[] ){
/* Create object of Locale class using contructor
Locale(String language, String country) */
Locale obj1 = new Locale("EN","US");
Locale obj2 = new Locale("CH","CHINA");
System.out.println("object obj1 of Locale class is : "+obj1);
System.out.println("object obj2 of Locale class is : "+obj2);
// getDisplayName() method call.
String name = obj1.getDisplayName(obj2);
System.out.println("Name for object obj1 : " + name);
name = obj2.getDisplayName(obj1);
System.out.println("Name for object obj2 : " + name);
}
} |
Output of the program.
object objLocale1 of Locale class is : en_US
object objLocale2 of Locale class is : ch_CHINA
Name for object obj1 : English (United States)
Name for object obj2 : Chamorro (CHINA) |
|