Previous | Next | Trail Map | Internationalization | Setting the Locale

Identifying Available Locales

You can create a Locale with any combination of valid language and country codes, but that doesn't mean you can use it. Remember, a Locale object is only an identifier. You pass the Locale object to other objects, which then do the real work. These other objects, which we call locale-sensitive, do not know how to deal with all possible Locale definitions.

To find out which types of Locale definitions a local-sensitive class recognizes, you invoke the getAvailableLocales method. For example, to find out which Locale definitions are supported by the DateFormat class, you could write a routine such as the following:

import java.util.*;
import java.text.*;

public class Available {

   static public void main(String[] args) {

      Locale list[] = DateFormat.getAvailableLocales();

      for (int i = 0; i < list.length; i++) {
          System.out.println
             (list[i].getLanguage() + " " + list[i].getCountry());
      }
   } 
} 


Previous | Next | Trail Map | Internationalization | Setting the Locale