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.

JavaData Integrity

Code

snippet
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

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.