Starting with JDK 9

JDK 9 can solve this problem using a single line of code. This is possible thanks to the new LocalDate.datesUntil(LocalDate endExclusive) method. This method returns  Stream<LocalDate> with an incremental step of one day:

startLocalDate.datesUntil(endLocalDate).forEach(System.out::println);

If the incremental step should be expressed in days, weeks, months, or years, then rely on LocalDate.datesUntil(LocalDate endExclusive, Period step). For example, an incremental step of 1 week can be specified as follows:

startLocalDate.datesUntil(endLocalDate, Period.ofWeeks(1)).forEach(System.out::println);

The output should be (weeks 1-8, weeks 8-15) as follows:

2019-02-01
2019-02-08
2019-02-15
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.151.107