从JAVA中的列表列表(不同类型)中获取元素

时间:2016-10-09 16:48:43

标签: java arraylist

请考虑以下代码并阅读我的评论。我正在寻找的是非常不言自明的。

import java.util.Arrays;
import java.util.List;

public class JavaApplication8 {

    public static void main(String[] args) {
        List<String> str0 = Arrays.asList("alif", "baa", "taa");
        List<Integer> str1 = Arrays.asList(1, 2, 3);
        List<Double> str2 = Arrays.asList(1.1, 2.2, 3.3);

        List<Object> everything = Arrays.asList(str0, str1, str2);

        // How can I get an element using index of index, as below
        System.out.println(everything.get(1).get(2));

        // I know this will work, but I don't want to get the element like this
        List<Integer> temp = (List<Integer>) everything.get(1);
        System.out.println(temp.get(2));
    }

}

有可能吗?

0 个答案:

没有答案