元に戻る
結局のところ、
import static java.time.DayOfWeek.SUNDAY; import java.time.YearMonth; import static java.time.temporal.TemporalAdjusters.dayOfWeekInMonth; public class ThirdSundays { public static void main(String[] args) { final YearMonth START = YearMonth.of(2016, 1); final YearMonth END = YearMonth.of(2017, 1); for (YearMonth d = START; d.isBefore(END); d = d.plusMonths(1)) { System.out.println( d.atDay(1).with(dayOfWeekInMonth(3, SUNDAY)) ); } } }
みたいな感じで落ち着くのか。こっちの方が何だか短いし。
こっちもStream使用版と同様に、
基本的にはLocalDate
をYearMonth
に置換しただけである。