Eng*_*r T -1 java collections enums composite-key
我在double []中有5个预定义值的数据集:
A = {1.5, 1.8, 1.9, 2.3, 2.7, 3.0}
B = {1.2, 1.8, 1.9, 2.4, 2.9, 3.1}
.
.
E = {1.4, 1.7, 1.8, 1.9, 2.3, 2.9}
Run Code Online (Sandbox Code Playgroud)
我如何在枚举中表示它?我想把它编码为:
private enum Solutions{
A(double[]),
B(double[]),
C(double[]),
D(double[]),
E(double[]) ;
private double[] val;
private Solutions(double[] pVal){
this.val = pVal;
}
}
Run Code Online (Sandbox Code Playgroud)
这可能吗?
要么
什么是最好的数据类型或数据结构在java中表示这个?除了上面的double []数组,用户还可以定义自己的自定义数组.
任何建议请.
我会使用varargs来表示你的潜在数字:
private Solutions(double... values) {
this.val = values;
}
Run Code Online (Sandbox Code Playgroud)
这将允许您传递任何可用的值:
A(12.4, 42.4, 30.2, 1.3),
B(39.2, 230.3, 230.0),
//etc...
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
882 次 |
最近记录: |