Java Locale getAvailableLocales() Method



Description

The Java Locale getAvailableLocales() method returns an array of all installed locales. The returned array represents the union of locales supported by the Java runtime environment and by installed LocaleServiceProvider implementations. It must contain at least a Locale instance equal to Locale.US.

Declaration

Following is the declaration for java.util.Locale.getAvailableLocales() method

public static Locale[] getAvailableLocales()

Parameters

NA

Return Value

This method returns an array of installed locales.

Exception

NA

Getting All Available Locales Example

The following example shows the usage of Java Locale getAvailableLocales() method. We're creating an array of available locales and then those locales are printed.

package com.tutorialspoint;

import java.util.Locale;

public class LocaleDemo {
   public static void main(String[] args) {

      // create a new array and get all installed locales
      Locale[] locales = Locale.getAvailableLocales();

      // print locales
      System.out.println("Installed locales are:");
      
      for (int i = 0; i < locales.length; i++) {
         System.out.println(i + ":" + locales[i]);
      }
   }
}

Output

Let us compile and run the above program, this will produce the following result −

Installed locales are:
0:
1:nn
2:ar_JO
3:bg
4:kea
5:nds
6:zu
7:am_ET
8:fr_DZ
...
741:mas_TZ
742:ti
743:kok
744:ewo
745:ms_BN
746:ccp_IN
747:br_FR
java_util_locale.htm
Advertisements