MonthDay with() Method in Java with Examples
with(Month month) method of the MonthDay class used to alter the month-of-year of MonthDay object using month passed as a parameter and after that method returns the copy of altered MonthDay.If the day-of-month value is invalid for the specified month after altering operation, the day will be adjusted to the last valid day-of-month.
public MonthDay with(Month month)
Parameters: This method accepts month as parameter which is the month-of-year to set in the returned month-day.
Return value: This method returns a MonthDay based on this month-day with the requested month
Below programs illustrate the with() method:
MonthDay before applying method: --08-28 MonthDay after applying method: --10-28
MonthDay before applying method: --10-31 MonthDay after applying method: --02-29
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.