fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.* ;
  8. import java.util.stream.* ;
  9. import java.time.temporal.* ;
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16.  
  17. List< LocalDate > firstSundayOfEachMonthInYear =
  18. Stream.of( Month.values() )
  19. .map( month ->
  20. Year
  21. .of( 2021 )
  22. .atMonth( month )
  23. .atDay( 1 )
  24. .with(
  25. TemporalAdjusters.firstInMonth( DayOfWeek.SUNDAY )
  26. )
  27. )
  28. .collect( Collectors.toList() )
  29. ;
  30.  
  31. System.out.println( firstSundayOfEachMonthInYear ) ;
  32.  
  33. }
  34. }
Success #stdin #stdout 0.11s 51264KB
stdin
Standard input is empty
stdout
[2021-01-03, 2021-02-07, 2021-03-07, 2021-04-04, 2021-05-02, 2021-06-06, 2021-07-04, 2021-08-01, 2021-09-05, 2021-10-03, 2021-11-07, 2021-12-05]