Java Locale getDisplayName() Example

Locale class getDisplayName() method example. This example shows you how to use getDisplayName() method.


Syntax is : public String getDisplayName()
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.

/**
 * @(#) GetDisplayNameLocale.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 GetDisplayNameLocale {
    public static void mainString 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);
     // getDisplayName() method call.
         String name = obj1.getDisplayName();
     System.out.println("Name for object obj1 : " + name);
     name = obj2.getDisplayName();
     System.out.println("Name for object obj2 : " + name);
  }
}

Output of the program.
object objLocale1 of Locale class is : english_US
object objLocale2 of Locale class is : chienese_CHINA
Name for object obj1 : english (United States)
Name for object obj2 : chienese (CHINA)

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US