我有一个Gs
类,定义了以下内容:
private static double[] r = new double[3];
我还为此数组创建了吸气剂/设置剂:
public static double[] getR() {
return r;
}
public static void setR(double[] r) {
Gs.r = r;
}
在另一个类中,我想在数组中设置值,例如只是r[1]
,但我不知道如何使用这些功能。
如何设置要将其值设置为的索引?
r[0], r[1], r[2]....
setter方法需要一个数组arg double[]
而不是double
,但是我不知道如何指定它。
答案 0 :(得分:1)
您可以将索引作为参数传递给getter和setter:
public static double getR(int index) {
return r[index];
}
public static void setR(int index, double r) {
Gs.r[index] = r;
}
答案 1 :(得分:0)
尝试
{"successStatus":0,"error":null,"response":{"items":[[0,"Value 0",0,"Value
0"],[1,"Value 1",1,"Value 1"],[2,"Value 2",2,"Value 2"],[3,"Value
3",3,"Value 3"],[4,"Value 4",4,"Value 4"],[5,"Value 5",5,"Value
5"],[6,"Value 6",6,"Value 6"],[7,"Value 7",7,"Value 7"],[8,"Value
8",8,"Value 8"],[9,"Value 9",9,"Value
9"]],"last":false,"queryId":10,"fieldsMetadata":[{"schemaName":"mycache1","typeName":"VALUE","fieldName":"KEY","fieldTypeName":"java.lang.Integer"},{"schemaName":"mycache1","typeName":"VALUE","fieldName":"VALUE","fieldTypeName":"java.lang.String"},{"schemaName":"mycache2","typeName":"VALUE","fieldName":"KEY","fieldTypeName":"java.lang.Integer"},{"schemaName":"mycache2","typeName":"VALUE","fieldName":"VALUE","fieldTypeName":"java.lang.String"}]},"sessionToken":null}
注意:这将立即设置整个阵列
答案 2 :(得分:0)
您只需在getter返回的数组上设置值:
Streams.zip(keyList.stream(), valueList.stream(), Maps::immutableEntry)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));