The parse(CharSequence) method of Year class is used to get an instance of Year from a string such as ‘2018’ passed as parameter. The string must have a valid value that can be converted to a Year. Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol.
public static Year parse(CharSequence text)
Parameters: This method accepts only one parameter text which represents the text to parse such as “2021”.
Return Value: This method returns the parsed year.
Exception: This method throws following Exceptions:
- DateTimeException: If the text cannot be parsed.
Below programs illustrate the parse(CharSequence text) 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.