The valueOf() method of ChronoUnit enum is used to return the enum unit of this type with the specified name.
public static ChronoUnit valueOf(String name)
Parameters: This method accepts name which is the name of the enum constant to be returned.
Return value: This method returns the enum constant with the specified name.
This method throws the following exception:
- IllegalArgumentException: if this enum type has no constant with the specified name.
- NullPointerException: if the argument is null.
Below programs illustrate the ChronoUnit.valueOf() 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.