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

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

在数组列表中,我有标签 - 字符串,我想将其更改为添加到其中的每个列表元素的另一个内容。我怎样才能做到这一点?

最佳答案

有两个地方需要更改。

改变

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

关于java - 更改每个列表元素的 ArrayList<?> 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21720173/

相关文章:

java - 从 java 中的结果集(oracle db)获取 BigInt 值

java - 使用 XMLAdapter 通过 jaxb 序列化通用字段

python - 从Python中的列表创建字典

java - 我不明白 System.out.println((char)b) 和 System.out.write((char)b) 之间的输出差异

java - 解析 Java 源代码

Delphi - 从由无类型指针填充的动态数组中访问数据

php - 用数组重写 PHP 函数

PHP - 将数组作为可变长度参数列表传递

list - 我正在尝试在 Racket 中编写一个函数(删除所有 xx elt),它返回一个新列表,其中删除了所有出现的 elt

list - 有关如何处理此 lisp 函数的建议。