【发布时间】:2022-01-03 23:36:59
【问题描述】:
我有一个 Excel 工作表中的单元格数组列表。我想从我实际拥有的单元格数组列表中创建大小为 50 的子数组列表,从索引 1590 开始,以 size()-700 结束。
我想从每个子数组列表中获取最大的数字并将其放入新的数组列表中。在新的 Arraylist 中应该只有每个 subarraylist 的最大值。
输入数据是我的单元格数组列表。
使用此代码,我得到了 50 多个数字,但它并不总是最高值。有人有想法吗?
这是我的代码:
int partitionSize = 50;
List<List<Cell>> partitions = new ArrayList<>();
List <Cell> high = new ArrayList();
Cell max = data.get(1590);
for (int i = 1590; i < data.size()-700; i += partitionSize) {
partitions.add(data.subList(i, Math.min(i + partitionSize, data.size()-700)));
}
for (List<Cell> list : partitions) {
for (int i = 1; i < list.size(); i++) {
if (list.get(i).getNumericCellValue() > max.getNumericCellValue()) {
max = list.get(i);
}
high.add(max);
}
}
【问题讨论】:
标签: java list arraylist collections sub-array