I have the following Integer list
List<Integer> arrayList = new ArrayList<Integer>();
for (int i = 0; i < 7; i++) {
arrayList.add(i);
}
So the list is like this [0,1,2,3,4,5,6]. My scenario is
If I give the value = 5 as parameter then I would like to split 5 sub list like this
[0,5], [1,6] , [2], [3], [4]
If I give the value = 4 as parameter then I would like to split 4 sub list like this
[0,4], [1,5], [2,6] , [3]
If I give the value = 3 as parameter then I would like to split 3 sub list like this
[0,3,6], [1,4], [2,5]
I already tested with below function but it is not my need.
public List<List<Integer>> chopped(List<Integer> list, final int splitCount) {
List<List<Integer>> parts = new ArrayList<List<Integer>>();
final int N = list.size();
for (int i = 0; i < N; i += splitCount) {
parts.add(new ArrayList<Notification>(list.subList(i, Math.min(N, i + splitCount))));
}
return parts;
}
At the above function, I give splitCount to 5 then the function returns
[0,1,2,3,4], [5,6]
The result I expect is [0,5], [1,6] , [2], [3], [4]