shailendra kushwah shailendra kushwah - 1 year ago 60
Java Question

How to get List list of Saturday for 2 years in Java

i am new in java i want to get list of Dates which have Saturday in Current and next year like 2016 and 2017.pls help

Answer Source

You can use the code below:

private List<Date> getSaturdayListOfCurrentYear(){
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_YEAR, 1);

    int firstDayOfTheYear = calendar.get(Calendar.DAY_OF_WEEK);
    int rangeToFirstSaturday = 7 - firstDayOfTheYear;
    int currentSaturdayOfYear = 1 + rangeToFirstSaturday;
    int daysInYear = calendar.getActualMaximum(Calendar.DAY_OF_YEAR);
    List<Date> saturdays = new ArrayList<Date>();

    while(currentSaturdayOfYear <= daysInYear){
        calendar.set(Calendar.DAY_OF_YEAR, currentSaturdayOfYear);
        currentSaturdayOfYear += 7;

    return saturdays;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download