The firstInMonth(DayOfWeek) method of a TemporalAdjusters class is used to return a TemporalAdjuster object which can be used to get a new Date object which is the first date of the same month with the same matching DayOfWeek as passed as a parameter from any Date object on which this TempotralAdjuster is applied.
public static TemporalAdjuster firstInMonth(DayOfWeek dayOfWeek)
Parameters: This method accepts dayOfWeek which can be used to get a new Date object which is the first date of the same month with the same matching DayOfWeek.
Return value: This method returns the first in month adjuster, not null.
Below programs illustrate the TemporalAdjusters.firstInMonth() method:
First date in month having sunday for localdate 2023-10-11 is: 2023-10-01
First date in a month having TUESDAY for localdate 2023-10-11 is: 2023-10-03
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.