Home Java Example Java Util Listing all available Locales

Related Tutorials


 
 

Share on Google+Share on Google+

Listing all available Locales

Advertisement
This section shows you how to list all the available locales installed with the software development kit.

Listing all available Locales

     

Locale is the class of java.util.*; package. This class represents the geographical, political and cultural region. Every tasks which requires to perform the operation is called local-sensitive. In this world, each places have it's own country name, language name etc. these can be determined by the object of the Locale class.

This section shows you how to list all the available locales installed with the software development kit. The given program in this section displays all the available language code, country code and full country name. Some following method and APIs which have used in the program for completion the task these are explained as follows:

Locale.getAvailableLocales():
Above method return a array of available locales which are installed with your software development kit.

Locale.getLanguage():
Above method returns the two character 'language code' for the specific locale. You can display the full language name by using the getDisplayLanguage() method of the Locale class.

Locale.getCounty():
Above method returns the two character country code for the specific locale. If you want to display the full country name then you can use the getDisplayCountry() method of Locale class.

Locale.getDisplayName():
Above method display the full description about the created locale that means the specific geographical or political or the cultural region.

Here is the code of the program:

import java.util.*;

public class Locales{
  public static void main(String[] args){
  Locale[] locales = Locale.getAvailableLocales();
  for(int i = 0; i < locales.length; i++){
  String language = locales[i].getLanguage();
  String country = locales[i].getCountry();
  String locale_name = locales[i].getDisplayName();
  System.out.println(i + ": " + language + ", " + country + ", 
+ locale_name);
  }
  }
}

Download this example.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 16, 2007

Related Tutorials

Discuss: Listing all available Locales   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
SAM
October 7, 2012
java

I have litle confusion with Locale class in java.util package that is how to operate with Array in this class and for which purpose.... reply soon
DMCA.com