LocalDate Dates Until Stream
Generate a date stream with LocalDate datesUntil, step it by weeks, and confirm the end date is excluded from the result.
Code
import java.time.LocalDate;
import java.time.Period;
import java.util.List;
public class Main {
public static void main(String[] args) {
LocalDate start = LocalDate.of(2026, 11, 1);
LocalDate end = LocalDate.of(2026, 11, 6);
// datesUntil returns a stream from start inclusive to end exclusive
List<LocalDate> days = start.datesUntil(end).toList();
System.out.println("days: " + days.size());
System.out.println("first: " + days.get(0));
System.out.println("last: " + days.get(days.size() - 1));
// a step period changes the spacing between generated dates
List<LocalDate> weekly = start.datesUntil(end, Period.ofWeeks(1)).toList();
System.out.println("weekly: " + weekly);
// an empty range produces an empty stream
System.out.println("empty: " + end.datesUntil(start).count());
// each date keeps its day-of-week value
start.datesUntil(end).forEach(date -> System.out.println(date + " " + date.getDayOfWeek()));
}
}What the code does
All of the logic lives in the class Main and the function main.
Watch out for
- Nothing to add to the project before running it.
Using it
The primary signature is public static void main(String[] args)
The demo output is labeled (days:, first:, last:), so every printed line maps back to its originating operation.
Key statements
List<LocalDate> weekly = start.datesUntil(end, Period.ofWeeks(1)).toList();
List<LocalDate> days = start.datesUntil(end).toList();
LocalDate start = LocalDate.of(2026, 11, 1);
Interactive Tools for This Topic
Age CalculatorCalculate exact age in years, months, and days between a birth date and a reference date, plus total days and the next birthday countdown.Business Days CalculatorCount the weekdays between two dates, excluding weekends and any holidays you list, and see how many calendar and weekend days are involved.Cron Next Runs CalculatorCompute the next scheduled run times for a standard five-field cron expression, supporting ranges, lists, steps, and day-of-week naming semantics.Duration ConverterConvert between human durations like 1w2d3h45m and total seconds, hours, and minutes with negative support.
FAQ
- What does LocalDate Dates Until Stream print when run?
- No setup needed: run the file and look for labeled lines like `days:`, `first:`, `last:` in the output.
Report a problem with this exampleOpens a pre-filled issue on GitHub.