更改每个列表元素的ArrayList <! - ? - >标记

时间:2014-02-12 06:19:46

标签: java arrays list arraylist tags

我有以下方法:

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;
    }

在arraylist中,我有标记 - 字符串,我想将它更改为每个列表元素的另一个,我添加到它。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

您需要更改两个地方。

更改

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[][]