Year parse(CharSequence) method in Java with Examples Last Updated : 30 Jul, 2019 Comments Improve Suggest changes Like Article Like Report 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. Syntax: 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: Program 1: Java // Java program to demonstrate // Year.parse(CharSequence text) method import java.time.*; public class GFG { public static void main(String[] args) { // create a Year object // using parse(CharSequence text) Year year = Year.parse("2019"); // print instance System.out.println("Year Parsed:" + year); } } Output: Year Parsed:2019 Program 2: Java // Java program to demonstrate // Year.parse(CharSequence text) method import java.time.*; public class GFG { public static void main(String[] args) { // create a Year object // using parse(CharSequence text) Year year = Year.parse("2018"); // print instance System.out.println("Year Parsed:" + year); } } Output: Year Parsed:2018 References: https://docs.oracle.com/javase/10/docs/api/java/time/Year.html#parse(java.lang.CharSequence) Comment More infoAdvertise with us Next Article Year parse(CharSequence) method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java java-basics Java-Functions Java-Year Practice Tags : Java Similar Reads YearMonth parse(CharSequence) method in Java with Examples The parse(CharSequence) method of YearMonth class used to get an instance of YearMonth from a string such as â2018-12â passed as parameter.The string must have a valid value that can be converted to a YearMonth object. The format of String must be uuuu-MM. YearMonths outside the range 0000 to 9999 m 2 min read MonthDay parse(CharSequence) method in Java with Examples The parse(CharSequence text) method of the MonthDay class in Java is used to get an instance of MonthDay from a text string. Syntax: public static MonthDay parse( CharSequence text) Parameters: This method accepts text as parameter to parse. Return value: This method returns the parsed month-day. Ex 1 min read Duration parse(CharSequence) method in Java with Examples The parse(CharSequence) method of Duration Class in java.time package is used to get a Duration from a string passed as the parameter. The format for the String to be parsed is "PnDTnHnMn.nS" where "nD" means 'n' number of Days, "nH" means 'n' number of Hours, "nM" means 'n' number of Minutes, "nS" 2 min read Pattern split(CharSequence) method in Java with Examples split(CharSequence) method of a Pattern class used to splits the given char sequence passed as parameter to method around matches of this pattern.This method can split charSequence into an array of String's, using the regular expression used to compile the pattern as a delimiter.so we can say that t 2 min read Year parse(CharSequence,DateTimeFormatter) method in Java with Examples The Year.parse(CharSequence, DateTimeFormatter) method of Year class is used to get an instance of Year from a string such as â2018â passed as parameter using a specificDateTimeFormatter.The Year is parsed using a specific DateTimeFormatter. The string must have a valid value that can be converted t 2 min read Like