You could either use Collectors.partitioningBy:
Map<Boolean, List<Integer>> map = list.stream().collect(Collectors.partitioningBy(element -> list.indexOf(element) >= 100));
and then do:
List<List<Integer>> results = new ArrayList(map.values());
Update:
Collectors.partitioningBy takes a predicate and thus is not able to solve the desired use case.
Or if you want to split a list into equal parts (what I think is more youre use case), you could use Collectors.groupingBy():
Map<Integer, List<Integer>> groups =
list.stream().collect(Collectors.groupingBy(element -> (element - 1) / YOUR_NUMBER_OF_PIECES_PER_SUBLIST));
List<List<Integer>> subLists= new ArrayList<List<Integer>>(groups.values());
System.out.println("Number of sublists " + subLists.size());
This gives you:
Number of sublists: 5
when running with NUMBER_OF_PIECES_PER_SUBLIST = 200, which seems your use case.
0, right?.subList(0, 100)has only 100 elements. Whereas.subList(101, 200)will have 99 elements.