I want to sort elements and group them as follows, How shall I achieve that using java streams sort, group and partition by.
The input is comming in streams that means after getting the below input after sometime the input like A16,17 may come the data structure must reorganize and regroup.
Input A10, A4, A11, A3, A12,A15 ....B19,B2,B20...
Output A3-A4,A10-A12,A15,B2,B19-B20.
I could able to sort as below
array.sort(Comparator .comparing(...)
.thenComparing(Comparator.comparing(...)));
but not sure how to partition and regroup for chaning input using streams in most optimised way.
array.stream().collect(Collectors.partitionBy(...))
What should be the logic in function for partition by in above in order to achieve serial order grouping ?