Has*_*hra 3 java arrays list java-8 java-stream
我有一个大小为 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
}
Run Code Online (Sandbox Code Playgroud)
我想要使用流 API 的代码。提前致谢
关于什么 :
List<List<Integer>> result = IntStream.range(0, list.size() / 100)
.mapToObj(index -> list.subList(index * 100, index * 100 + 100))
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)