Java Data Type How to - Get date for days in current week








Question

We would like to know how to get date for days in current week.

Answer

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import static java.util.stream.Collectors.toList;
public class Main {
//w ww  . j  a v a2 s .co  m
  public static void main(String[] args) {

    System.out.println(daysInWeek(LocalDate.now()));
  }

  public static List<LocalDate> daysInWeek(LocalDate dayInWeek) {
    return Arrays.asList(DayOfWeek.values()).stream().map(dayInWeek::with)
        .collect(toList());
  }
}

The code above generates the following result.