我有以下方法:
public String[][] launch(){
String[][] result = new String[2][];
for (int i = 0; i<2; i++){
device.pressHome();
ui.wait(500);
ui.close();
ui.close();
ui.openProgram("ON");
long TStart = System.currentTimeMillis();
ui.detectContactList();
long TStop = System.currentTimeMillis();
float res = TStop - TStart;
res /= 1000;
ui.log("[loading time]: "+ res);
ArrayList<String> attemptList = new ArrayList<String>();
attemptList.add("Loading time");
attemptList.add(Integer.toString(i));
attemptList.add(Float.toString(res));
result[i] = attemptList.toArray(new String[attemptList.size()]);
System.out.println(attemptList);
}
return result;
}
在数组列表中,我有标签 - 字符串,我想为每个列表元素将其更改为另一个内容,并添加到其中。我该怎么做?
您需要更改两个位置。
改变
String[][] result = new String[2][];
自
Object[][] result = new Object[2][];
和
ArrayList<String> attemptList = new ArrayList<String>();
自
ArrayList<Object> attemptList = new ArrayList<Object>();
添加这样的元素
ArrayList<Object> attemptList = new ArrayList<Object>();
attemptList.add("Loading time");
attemptList.add(10);
attemptList.add(10f);
最后,您需要将返回类型更改为Object[][]