Month of() method in Java
The of() method is a built-in method of the Month ENUM which is used to generate a Month instance from an integer value. The integer value should be in the range 1-12 representing any of the 12 months and the method generates a Month instance from it representing a month-of-year.
public static Month of(int month)
Parameters: This method accepts a single parameter month, which is of integer type.
Return Value: This method returns the corresponding Month instance generated using the parameter passed.
Exception: This method throws a DateTimeException if the month of year passed to the parameter is not valid.
Below programs illustrate the above method:
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.