ChoiceFormat setChoices() method in Java with Examples Last Updated : 16 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The setChoices() method of java.text.ChoiceFormat class is used to set the new Choice item with a defined limit and format in Choiceformat object. Syntax: public void setChoices(double[] limits, String[] formats) Parameter: This method takes the following parameters: limits: which is the array of double values which will contain limit for choiceitem. format: which is the array of string values which will contain the format for choiceitem. Return Value: This method does not return anything. Exception: This method throws NullPointerException if limit or format is null. Below are the examples to illustrate the setChoices() method: Example 1: Java // Java program to demonstrate // setChoices() 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 new double array double[] newlimit = { 1, 2, 3 }; // creating and initializing new String array String[] newformat = { "sun", "mon", "tue" }; // setting the limit and format in // ChoiceFormat Object // using setChoices() method cf1.setChoices(newlimit, newformat); // display the result System.out.print("updated Choiceformat object: " + cf1.toPattern()); } catch (NullPointerException e) { System.out.println("\nLimit or Format is null"); System.out.println("Exception thrown: " + e); } } } Output: updated Choiceformat object: 1.0#sun|2.0#mon|3.0#tue Example 2: Java // Java program to demonstrate // setChoices() 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 new double array double[] newlimit = null; // creating and initializing new String array String[] newformat = { "sun", "mon", "tue" }; // setting the limit and format in // ChoiceFormat Object // using setChoices() method cf1.setChoices(newlimit, newformat); // display the result System.out.print("updated Choiceformat object: " + cf1.toPattern()); } catch (NullPointerException e) { System.out.println("Limit or Format is null"); System.out.println("Exception thrown: " + e); } } } Output: Limit or Format is null Exception thrown: java.lang.NullPointerException Reference: https://docs.oracle.com/javase/9/docs/api/java/text/ChoiceFormat.html#setChoices-double:A-java.lang.String:A- Comment More infoAdvertise with us Next Article ChoiceFormat setChoices() method in Java with Examples R rohitprasad3 Follow Improve Article Tags : Java Java-Functions Java-text package Java- ChoiceFormat Practice Tags : Java Similar Reads ChoiceFormat equals() method in Java with Examples The equals() method of java.text.ChoiceFormat class is used to compare between two ChoiceFormat objects and give the Boolean value regarding the comparison.Syntax: public boolean equals(Object obj) Parameter: This method takes obj as parameter which is another ChoiceFormat object for comparison.Retu 2 min read ChoiceFormat format() method in Java with Examples The format() method of java.text.ChoiceFormat class is used to get the appended string builder of the format value of particular limit value passed as parameter and text passed as parameter in this method. Syntax: public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition statu 2 min read ChoiceFormat getLimits() method in Java with Examples The getLimits() method of java.text.ChoiceFormat class is used to get the attached limit to choice format object in time of initialization. It returns the array of double type with the limits.Syntax: public double[] getLimits() Parameter: This method does not accept any parameter.Return Value: This 2 min read ChoiceFormat hashCode() method in Java with Examples The hashCode() method of java.text.ChoiceFormat class is used to get the hash code for choice format object. This hashcode value is returned as an integer. Syntax: public int hashCode() Parameter: This method does not accept any parameter. Return Value: This method returns hash code for choice forma 2 min read ChoiceFormat applyPattern() method in Java with Examples The applyPattern() method of java.text.ChoiceFormat class is used to set the new pattern text for current ChoiceFormat by overriding the current limit and format. This new pattern will be the combination of limit and format of ChoiceFormatSyntax: public void applyPattern(String newPattern) Parameter 2 min read Like