Get an array of Holidays

 Problem:

You want to know what holidays are common for a locale.

Solution:

Icu4j contains a system to help the Java developer handle international holidays.  The Holiday class is simple to use, and has failry complete data.

 

To get an Array of all Holidays for Mexico:

//Get a ULocale

ULocale locale = new ULocale("es_MX");

//Get an array of Holidays

Holiday[] holidays = Holiday.getHolidays(locale);

//Loop through all of the Holidays and output the localized display name

for(int x = 0; x < holidays.length; x++){

    System.out.println(holidays[x].getDisplayName(locale));

}

 

The output:

 

New Year's Day

Constitution Day

Benito Juárez Day

May Day

Cinco de Mayo

Navy Day

Independence Day

Día de la Raza

All Saints' Day

Day of the Dead

Revolution Day

Flag Day

Christmas