/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import java.time.* ; import java.time.temporal.* ; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { { List<LocalDate> mondays = new ArrayList<>() ; List<LocalDate> wednesdays = new ArrayList<>() ; List<LocalDate> thursdays = new ArrayList<>() ; LocalDate today = LocalDate.now( ZoneId.of( "America/Montreal" ) ) ; LocalDate twoMonthsLater = today.plusMonths( 2 ); LocalDate localDate = today ; while ( localDate.isBefore( twoMonthsLater ) ) { DayOfWeek dow = localDate.getDayOfWeek() ; switch ( dow ) { case MONDAY: mondays.add( localDate ) ; break; case WEDNESDAY: wednesdays.add( localDate ) ; break; case THURSDAY: thursdays.add( localDate ) ; break; default: // Ignore any other day-of-week. break; } // Set-up the next loop. localDate = localDate.plusDays( 1 ) ; } } }
Standard input is empty
From 2017-10-17 to 2017-12-17: mondays: [2017-10-23, 2017-10-30, 2017-11-06, 2017-11-13, 2017-11-20, 2017-11-27, 2017-12-04, 2017-12-11] wednesdays: [2017-10-18, 2017-10-25, 2017-11-01, 2017-11-08, 2017-11-15, 2017-11-22, 2017-11-29, 2017-12-06, 2017-12-13] thursdays: [2017-10-19, 2017-10-26, 2017-11-02, 2017-11-09, 2017-11-16, 2017-11-23, 2017-11-30, 2017-12-07, 2017-12-14]