The nextOrSame(DayOfWeek) method of a TemporalAdjusters class is used to return a next-or-same DayOfWeek TemporalAdjuster object which can be used to get a new Date object which is the next-or-same date with the same DayOfWeek specified as the parameter, from any Date object on which this TempotralAdjuster is applied.
public static TemporalAdjuster nextOrSame(DayOfWeek dayOfWeek)
Parameters: This method accepts dayOfWeek which can be used to get a new Date object which is the next-or-same date with the same DayOfWeek
Return value: This method returns the next-or-same DayOfWeek adjuster.
Below programs illustrate the TemporalAdjusters.nextOrSame() method:
Next or same date having WEDNESDAY for localdate 2020-10-31 is: 2020-11-04
Next or same date having WEDNESDAY for localdate 2020-02-27 is: 2020-02-27
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.