首页 > 解决方案 > 获取每个数组列表中的最小值

问题描述

我正在做一个对成绩进行排序的程序。它比较了arrayslist的3个arraylist,我试图在1中获得最小的节点,在2中获得中等节点,在3中获得更大的节点。然后将其保存到1、2或3级。

以下代码不断重复节点。有人知道为什么吗?有什么建议么?

ArrayList<ArrayList<Double>> y = new ArrayList<ArrayList<Double>>(); // ->have 10 nodes in them of 10 elements each
ArrayList<ArrayList<Double>> y2 = new ArrayList<ArrayList<Double>>(); // ->have 10 nodes in them of 10 elements each
ArrayList<ArrayList<Double>> y3 = new ArrayList<ArrayList<Double>>(); // ->have 10 nodes in them of 10 elements each

for (int j = 0; j < y.size(); j++) {
    for (int k = 0; k < y.get(j).size(); k++) {
        if (y.get(j).get(k) < y2.get(j).get(k) && y.get(j).get(k) < y3.get(j).get(k)) {
            grades.get(j).remove(14);
            grades.get(j).add(14, 1.00);
            grades2.add(grades.get(j));
        }
        if (y2.get(j).get(k) < y3.get(j).get(k)) {
            grades.get(j).remove(14);
            grades.get(j).add(14, 2.00);
            grades2.add(grades.get(j));

        } else {
            grades.get(j).remove(14);
            grades.get(j).add(14, 3.00);
            grades3.add(grades.get(j));
        }
    }
}

标签: javaarraylist

解决方案


推荐阅读