Java Calendar getAvailableLocales() Method



Description

The Java Calendar getAvailableLocales() method returns an array of locales for which the getInstance methods of this class can return localized instances.

Declaration

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

public static Locale[] getAvailableLocales()

Parameters

NA

Return Value

Returns an array of locales for which localized Calendar instances are available.

Exception

NA

Getting Available Locales Example

The following example shows the usage of Java Calendar getAvailableLocales() method. An array of locale is retrieved using Calendar.getAvailableLocales() method. We're printing total locales count and printing first ten locales.

package com.tutorialspoint;

import java.util.Calendar;
import java.util.Locale;

public class CalendarDemo {
   public static void main(String[] args) {
      Locale[] array = Calendar.getAvailableLocales();

      System.out.println("Total locale: " + array.length);
      System.out.println("First 10 Locales");
      for (int i = 0; i < 10; i++) {
         System.out.println(array[i]);
      }
   }
}

Output

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

Total locale: 748
First 10 Locales

nn
ar_JO
bg
kea
nds
zu
am_ET
fr_DZ
ti_ET

Getting Available Locales from GregorianCalendar Example

The following example shows the usage of Java Calendar getAvailableLocales() method. An array of locale is retrieved using GregorianCalendar.getAvailableLocales() method. We're printing total locales count and printing first ten locales.

package com.tutorialspoint;

import java.util.GregorianCalendar;
import java.util.Locale;

public class CalendarDemo {
   public static void main(String[] args) {
      Locale[] array = GregorianCalendar.getAvailableLocales();

      System.out.println("Total locale: " + array.length);
      System.out.println("First 10 Locales");
      for (int i = 0; i < 10; i++) {
         System.out.println(array[i]);
      }
   }
}

Output

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

Total locale: 748
First 10 Locales

nn
ar_JO
bg
kea
nds
zu
am_ET
fr_DZ
ti_ET

Getting Available Locales from Current Dated Calendar Instance Example

The following example shows the usage of Java Calendar getAvailableLocales() method. An array of locale is retrieved using getAvailableLocales() method of a calendar instance. We're printing total locales count and printing first ten locales.

package com.tutorialspoint;

import java.util.Calendar;
import java.util.Locale;

public class CalendarDemo {
   public static void main(String[] args) {
      Locale[] array = Calendar.getInstance().getAvailableLocales();

      System.out.println("Total locale: " + array.length);
      System.out.println("First 10 Locales");
      for (int i = 0; i < 10; i++) {
         System.out.println(array[i]);
      }
   }
}

Output

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

Total locale: 748
First 10 Locales

nn
ar_JO
bg
kea
nds
zu
am_ET
fr_DZ
ti_ET
java_util_calendar.htm
Advertisements