Java中的数组列表的数组

我正在写这样的东西。TreeMap<Double, List<double[]>[]> tm = new TreeMap<>();在我的eclipse中好像不行,因为里面的代码init可以识别我想要的数据类型。总是有错误。我可以这样做吗?或者怎么做这种事情?


private static void init(TreeMap<Double, List<Double>[]> tm, List<double[]> ll) {

    for(double[] a:ll) {

        if(!tm.containsKey(a[0])) {

            List[] ab= new List[2];

            tm.put(new Double(a[0]),ab);

            tm.get(a[0])[0] = new LinkedList<double[]>();

            tm.get(a[0])[1] = new LinkedList<double[]>();

        }

        List<Double[]>[] b = tm.get(a[0]);

    }

}


public static void main(String[] args) {

    // TODO Auto-generated method stub

    TreeMap<Double, List<double[]>[]> tm = new TreeMap<>();

    List<double[]> ll = new LinkedList<>();

    ll.add(new double[] {-3,2.2});

    ll.add(new double[] {1,5.3});

    ll.add(new double[] {-1.3,4});

    ll.add(new double[] {8,22});

    init(tm,ll);

}



蝴蝶刀刀
浏览 151回答 2
2回答

有只小跳蛙

List<double[]>[]是不正确的。List<T>已经表明它是T.所以,一定是&nbsp;List<double[]>不过,我看你是想传递一个TreeMap<Double, List<double[]>>到&nbsp;TreeMap<Double, List<Double[]>>这是行不通的。编译器无法double[]将 a装箱(或拆箱)到 a&nbsp;Double[]。使两者保持一致,它应该可以工作。

PIPIONE

private static void init(TreeMap<Double, List<double[]>[]> tm, List<double[]> ll) {for(double[] a:ll) {&nbsp; &nbsp; if(!tm.containsKey(a[0])) {&nbsp; &nbsp; &nbsp; &nbsp; List[] ab= new List[2];&nbsp; &nbsp; &nbsp; &nbsp; tm.put(new Double(a[0]),ab);&nbsp; &nbsp; &nbsp; &nbsp; tm.get(a[0])[0] = new LinkedList<double[]>();&nbsp; &nbsp; &nbsp; &nbsp; tm.get(a[0])[1] = new LinkedList<double[]>();&nbsp; &nbsp; }&nbsp; &nbsp; List<double[]>[] b = tm.get(a[0]);}}public static void main(String[] args) {// TODO Auto-generated method stubTreeMap<Double, List<double[]>[]> tm = new TreeMap<>();List<double[]> ll = new LinkedList<>();ll.add(new double[] {-3,2.2});ll.add(new double[] {1,5.3});ll.add(new double[] {-1.3,4});ll.add(new double[] {8,22});init(tm,ll);}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java