如何引用 returns 数组的方法并为数组分配新值?
How to reference a method that returns an array and assign a new value to the array?
我正在尝试通过 returns 同一 class 中的数组的方法访问数组。然后我需要写回数组以备将来使用。这是到目前为止的代码:```
public int [] unitSelection(){
int [] selectedUnits = new int[numberCheck()];
return selectedUnits;
for (int i = 0; i < checkBoxList.length; i++) {
if (checkBoxList[i] == e.getSource()) {
index = i;
unitSelection()[i] = index;
export_to_SRF.setEnabled(true);
}
```
代码“unitSelection()[i]”应该更新“unitSelected”方法中“selectedUnits”数组中的数组。我一直在阅读,但找不到与引用外部方法数组有关的任何内容。提前致谢
for (int i = 0; i < checkBoxList.length; i++) {
if (checkBoxList[i] == e.getSource()) {
index = i;
int[] x = unitSelection();
x[i] = index;
export_to_SRF.setEnabled(true);
}
但我认为这不会如您所愿。 unitSelection()
returns 每次一个新数组,这样实际上不会更新数组。
我正在尝试通过 returns 同一 class 中的数组的方法访问数组。然后我需要写回数组以备将来使用。这是到目前为止的代码:```
public int [] unitSelection(){
int [] selectedUnits = new int[numberCheck()];
return selectedUnits;
for (int i = 0; i < checkBoxList.length; i++) {
if (checkBoxList[i] == e.getSource()) {
index = i;
unitSelection()[i] = index;
export_to_SRF.setEnabled(true);
}
```
代码“unitSelection()[i]”应该更新“unitSelected”方法中“selectedUnits”数组中的数组。我一直在阅读,但找不到与引用外部方法数组有关的任何内容。提前致谢
for (int i = 0; i < checkBoxList.length; i++) {
if (checkBoxList[i] == e.getSource()) {
index = i;
int[] x = unitSelection();
x[i] = index;
export_to_SRF.setEnabled(true);
}
但我认为这不会如您所愿。 unitSelection()
returns 每次一个新数组,这样实际上不会更新数组。