当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java ChoiceFormat getLimits()用法及代码示例


java.text.ChoiceFormat类的getLimits()方法用于在初始化时获取选择格式对象的附加限制。它返回带有限制的double类型数组。

用法:

public double[] getLimits()

参数:此方法不接受任何参数。


返回值:此方法返回附加到选择格式对象的限制。

下面是说明getLimits()方法的示例:

示例1:

// 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)); 
    } 
}
输出:
Limit: [4.0, 5.0, 6.0, 7.0]

示例2:

// 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[] forma = 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–



相关用法


注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 ChoiceFormat getLimits() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。