【发布时间】:2022-01-11 22:12:58
【问题描述】:
我在获取SubarrayLists 时遇到问题。
我有一个班级Accgy。它包括一个 Excelsheet 的 4 个单元格(单元格 y、x、z 、acc)。
public class Accgy {
Cell y;
Cell x;
Cell z;
Cell acc;
public Accgy(Cell x, Cell y, Cell z, Cell acc) {
this.y = y;
this.x = x;
this.z = z;
this.acc = acc;
}
Cell getCellz() { return z; }
Cell getCelly() { return y; }
Cell getCellx() { return x; }
Cell getCellacc() { return acc; }
}
在 Excelsheet 中,A x,y 和 z 是一行。在ArrayListaccgy里面有Excelsheet的所有值
我有来自 Arraylist maxPerRange 中另一个 Excelsheet B 的值。
在这个 Arraylist 中,只有 Excelsheet B 的最高值。
两个 Excelsheet 的行数相同。
我想创建一个 Arraylist,它执行 ArrayList accgy 的子数组列表,索引从 1590 开始,到 accgy.size()-700 结束。但条件是如果ArrayListaccgy和rowIndex的值与ArrayListmaxPerRangerowIndex的值相同,则要把ArrayList划分到subArrayLists中。
我想在 subArraylist 中的 ArrayList accgy 的所有值在 maxPerRange 的 rowIndex 之间。所以maxPerRange 的rowIndex 应该像边框。
subArraylist 中的值应该从一个maxPerRange 到下一个maxPerRange。
我希望能清楚地解释我的问题。
这是我到目前为止所拥有的代码。
我认为一个错误是partitions1.add(accgy.subList(i, accgy.size() - 700));
但我不确定。我希望有人可以帮助我。
List<List<Accgy>> partitions1 = new ArrayList<>();
for (int i = 1590; i < accgy.size() - 700; i++) {
for (int j = 0; j < maxPerRange.size(); j++) {
if (accgy.get(i).getCellx().getRowIndex() == maxPerRange.get(j).getRowIndex()) {
partitions1.add(accgy.subList(i, accgy.size() - 700));
}
}
}
for (List<Accgy> c : partitions1) {
for (Accgy g : c) {
System.out.println(g.getCellx().getNumericCellValue());
System.out.println(g.getCellx().getRowIndex());
}
}
【问题讨论】:
标签: java list arraylist collections sublist