gpt4 book ai didi

java - 如何使用流API将数组划分为子数组

转载 作者:行者123 更新时间:2023-12-02 14:11:33 25 4
gpt4 key购买 nike

我有一个大小为 1000 的数组。我想使用流操作来执行这样的操作:-

List list= new ArrayList();
//list is initialize to 1000 elements

List subList = list.subList(0, 100);
// perform some operaions over the subarray
List subList1 = list.subList(101, 200);
// perform some operaions over the subarray
.... so on
}

我想要使用流 API 的代码。提前致谢

最佳答案

关于:

  List<List<Integer>> result = IntStream.range(0, list.size() / 100)
.mapToObj(index -> list.subList(index * 100, index * 100 + 100))
.collect(Collectors.toList());

关于java - 如何使用流API将数组划分为子数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55625888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com