Java Calendar getAvailableCalendarTypes() Method



Description

The Java Calendar getAvailableCalendarTypes() method returns an unmodifiable set of all calendar types which are supported by the calendar in the run time environment.

Declaration

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

public static Set<String> getAvailableCalendarTypes()

Parameters

NA

Return Value

Returns an unmodifiable Set containing all available calendar types.

Exception

NA

Getting Available Calendar Types of Calendar Instance Example

The following example shows the usage of Java Calendar getAvailableCalendarTypes() method. An unmodifiable set of calendar type is retrieved using Calendar.getAvailableCalendarTypes() method. We're printing the set thereafter.

package com.tutorialspoint;

import java.util.Calendar;
import java.util.Set;

public class CalendarDemo {
   public static void main(String[] args) {
      Set<String> set = Calendar.getAvailableCalendarTypes();

      System.out.println("Available Calendar Types: " + set);
   }
}

Output

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

Available Calendar Types: [gregory, buddhist, japanese]

Getting Available Calendar Types of GregorianCalendar Instance Example

The following example shows the usage of Java Calendar getAvailableCalendarTypes() method. An unmodifiable set of calendar type is retrieved using GregorianCalendar.getAvailableCalendarTypes() method. We're printing the set thereafter.

package com.tutorialspoint;

import java.util.GregorianCalendar;
import java.util.Set;

public class CalendarDemo {
   public static void main(String[] args) {
      Set<String> set = GregorianCalendar.getAvailableCalendarTypes();

      System.out.println("Available Calendar Types: " + set);
   }
}

Output

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

Available Calendar Types: [gregory, buddhist, japanese]

Getting Available Calendar Types from Current Dated Calendar Instance Example

The following example shows the usage of Java Calendar getAvailableCalendarTypes() method. An array of locale is retrieved using getAvailableCalendarTypes() 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.Set;

public class CalendarDemo {
   public static void main(String[] args) {
      Set<String> set = Calendar.getInstance().getAvailableCalendarTypes();

      System.out.println("Available Calendar Types: " + set);
   }
}

Output

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

Available Calendar Types: [gregory, buddhist, japanese]
java_util_calendar.htm
Advertisements