Tuesday, February 3, 2026
HomeLanguagesJavaChoiceFormat getLimits() method in Java with Examples

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 method returns limit attached to the choice format object.
Below are the examples to illustrate the getLimits() method:
Example 1: 
 

Java




// Java program to demonstrate getLimits() method
 
import java.text.*;
import java.util.*;
import java.io.*;
 
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing ChoiceFormat
        ChoiceFormat cf
            = new ChoiceFormat(
                "4#wed| 5#thu | 6#fri | 7#sat");
 
        // getting limit attached to the ChoiceFormat
        // using getLimits() method
        double[] format = cf.getLimits();
 
        // display the result
        System.out.print("Limit: "
                         + Arrays.toString(format));
    }
}


Output: 

Limit: [4.0, 5.0, 6.0, 7.0]

 

Example 2: 
 

Java




// Java program to demonstrate getLimits() method
 
import java.text.*;
import java.util.*;
import java.io.*;
 
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing limit
        double[] limit = { 1, 2, 3, 4 };
 
        // creating and initializing format
        String[] format
            = { "add", "sub", "multiply", "divide" };
 
        // creating and initializing ChoiceFormat
        ChoiceFormat cf
            = new ChoiceFormat(limit, format);
 
        // getting limit attached to the ChoiceFormat
        // using getLimits() method
        double[] format = cf.getLimits();
 
        // display the result
        System.out.print("Limit: "
                         + Arrays.toString(format));
    }
}


Output: 

Limit: [add, sub, multiply, divide]

 

Reference: https://docs.oracle.com/javase/9/docs/api/java/text/ChoiceFormat.html#getLimits–
 

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32478 POSTS0 COMMENTS
Milvus
124 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11979 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12066 POSTS0 COMMENTS
Shaida Kate Naidoo
6987 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6935 POSTS0 COMMENTS
Umr Jansen
6919 POSTS0 COMMENTS