Java Locale getDisplayVariant() Example
Locale class getDisplayVariant() method example. This example shows you how to use getDisplayVariant() method.
Syntax is : public String getDisplayVariant(Locale inLocale)
Method returns a name for the locale's variant code that is appropriate for display to the user. If possible, the name will be localized for
inLocale. If the locale doesn't specify a variant code, this function returns the empty string.
Here is the code.
/**
* @(#) GetDisplayVariant1Locale.java
* A class representing use of method getDisplayVariant() of Locale class
in java.util Package.
* @Version 26-May-2008
* @author Rose India Team
*/
import java.util.*;
class GetDisplayVariant1Locale {
public static void main( String args[] ){
/* Create object of Locale class using contructor
Locale(String language, String country, String variant) */
Locale obj1 = new Locale("fr","FR","MAC");
Locale obj2 = new Locale("ITALIAN","ITALY","WIN");
System.out.println("object obj1 of Locale class is : "+obj1);
System.out.println("object obj2 of Locale class is : "+obj2);
// getDisplayVariant() method call.
String variant = obj1.getDisplayVariant(obj2);
System.out.println("Variant for object obj1 : " + variant);
variant = obj2.getDisplayVariant(obj1);
System.out.println("Variant for object obj2 : " + variant);
}
} |
Output of the program.
object objLocale1 of Locale class is : fr_FR_MAC
object objLocale2 of Locale class is : italian_ITALY_WI
Variant for object obj1 : MAC
Variant for object obj2 : WI |
|