Java Program to get date for all the days of the current week

Java 8Object Oriented ProgrammingProgramming

At first, get the current date:

LocalDate listDays = LocalDate.now();

Now, get the date for all the days of the current week:

Arrays.asList(DayOfWeek.values()).stream().map(listDays::with).collect(toList()));

Example

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.Arrays;
import static java.util.stream.Collectors.toList;
public class Demo {
   public static void main(String[] args) {
      LocalDate listDays = LocalDate.now();
      System.out.println("All the dates for the days in the week =
         \n"+Arrays.asList(DayOfWeek.values()).stream().map(listDays::with).collect(toList()));
   }
}

Output

All the dates for the days in the week =
[2019-04-15, 2019-04-16, 2019-04-17, 2019-04-18, 2019-04-19, 2019-04-20, 2019-04-21]
raja
Published on 24-Apr-2019 16:10:00
Advertisements