Java Locale toString() Example
Locale class toString() method example. This example shows you how to use toString() method.
Syntax is : public final String toString()
Method returns programmatic name of the entire locale, with the language, country and variant separated by underbars. Language is
always lower case, and country is always upper case. If the language is missing, the string will begin with an underbar. If both the
language and country fields are missing, this function will return the empty string. You can't have a locale with only a variant.
Here is the code.
/**
* @(#) ToStringLocale.java
* A class representing use of method toString() of Locale class
in java.util Package.
* @Version 24-May-2008
* @author Rose India Team
*/
import java.util.*;
class ToStringLocale {
public static void main( String args[] ){
/* Create object of Locale class using contructor
Locale(String language, String country, String variant) */
Locale obj1 = new Locale("ENGLISh", "Us", "WIN");
Locale obj2 = new Locale("CHINESE", "China", "MAC");
System.out.println("object obj1 of Locale class is : "+obj1);
System.out.println("object obj2 of Locale class is : "+obj2);
// toString() method call.
String strValue = obj1.toString();
System.out.println("String representation of object obj1 : "+strValue);
strValue = obj2.toString();
System.out.println("String representation of object obj2 : "+strValue);
}
} |
Output of the program.
object obj1 of Locale class is : english_US_WIN
object obj2 of Locale class is : chinese_CHINA_MAC
String representation of object obj1 : english_US_WIN
String representation of object obj2 : chinese_CHINA_MAC |
|