📌  相关文章
📜  Java中的 ChoiceFormat getLimits() 方法及示例

📅  最后修改于: 2022-05-13 01:55:16.134000             🧑  作者: Mango

Java中的 ChoiceFormat getLimits() 方法及示例

Java.text.ChoiceFormat类的getLimits()方法用于在初始化时获取选择格式对象的附加限制。它返回具有限制的双精度类型数组。
句法:

public double[] getLimits()

参数:此方法不接受任何参数。
返回值:此方法返回附加到选择格式对象的限制。
以下是说明getLimits()方法的示例:
示例 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));
    }
}


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));
    }
}


输出:
Limit: [4.0, 5.0, 6.0, 7.0]

示例 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));
    }
}
输出:
Limit: [add, sub, multiply, divide]

参考: https://docs.oracle.com/javase/9/docs/api/ Java/text/ChoiceFormat.html#getLimits–