ChoiceFormat parse() method in Java with Examples Last Updated : 20 Jan, 2023 Comments Improve Suggest changes Like Article Like Report The parse() method of java.text.ChoiceFormat class is used to get the limit value for particular format in ChoiceFormat object. Syntax: public Number parse(String text, ParsePosition status) Parameter: This method takes the following parameters: text: which is the text for which limit value have to be found in String format.status: which is the index at the which that choice item is present for which limit value to be found. Return Value: This method returns an array of the specified type which is the format attached to the ChoiceFormat object. Exception: This method throws NullPointerException if string text or status is null. Below are the examples to illustrate the parse() method: Example 1: Java // Java program to demonstrate // parse() method import java.text.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { try { // creating and initializing ChoiceFormat ChoiceFormat cf1 = new ChoiceFormat( "4#wed| 5#thu | 6#fri | 7#sat"); // creating and initializing ParsePosition ParsePosition par = new ParsePosition(0); // getting limit of particular format // of ChoiceFormat Object // using parse() method Number limit = cf1.parse("wed", par); // display the result System.out.print("limit: " + limit.intValue()); } catch (NullPointerException e) { System.out.println("\nString is Null"); System.out.println("Exception thrown: " + e); } } } Output:limit: 4 Example 2: Java // Java program to demonstrate // parse() method import java.text.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { try { // creating and initializing ChoiceFormat ChoiceFormat cf1 = new ChoiceFormat( "4#wed| 5#thu | 6#fri | 7#sat"); // creating and initializing ParsePosition ParsePosition par = new ParsePosition(0); // getting limit of particular format // of ChoiceFormat Object // using parse() method Number limit = cf1.parse(null, par); // display the result System.out.print("limit: " + limit.intValue()); } catch (NullPointerException e) { System.out.println("String is Null"); System.out.println("Exception thrown: " + e); } } } Output:String is Null Exception thrown: java.lang.NullPointerException Reference: https://docs.oracle.com/javase/9/docs/api/java/text/ChoiceFormat.html#parse-java.lang.String-java.text.ParsePosition- Comment More infoAdvertise with us Next Article ChoiceFormat parse() method in Java with Examples R rohitprasad3 Follow Improve Article Tags : Java Java-Functions Java-text package Java- ChoiceFormat Practice Tags : Java Similar Reads 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 Year parse(CharSequence) method in Java with Examples 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 stat 2 min read Double parseDouble() method in Java with examples The parseDouble() method of Java Double class is a built in method in Java that returns a new double initialized to the value represented by the specified String, as done by the valueOf method of class Double. Syntax: public static double parseDouble(String s) Parameters: It accepts a single mandato 2 min read Boolean parseBoolean() method in Java with examples The parseBoolean() method of Boolean Class is a built in static method of the class java.lang.Boolean which is used to convert a given string to its boolean value. Syntax: Boolean.parseBoolean(String value) Parameters: It takes one parameter value of type string which contains the value which is to 2 min read Level parse() method in Java with Examples The parse() method of java.util.logging.Level is used to parse a level name string into a Level. The name of the logging level must be a valid logging name. The argument string may consist of either a level name or an integer value. Level example name: "INFO", "800". Syntax: public static Level pars 2 min read Like