I've a list of elements into a list. Those elements are returned ordered into a Object[]. In that array the first element is a Document
, the second is a DocumentRow
.
I'm grouping all rows that belong to the same document together using the groupingBy
function.
List<Object[]> rows = documentRowRepository.rowsExportSTS(from, until);
Map<Document, List<DocumentRow>> rowsGroupedByDocument =
rows.stream()
.map(r -> (DocumentRow) r[1])
.collect(Collectors.groupingBy(r -> r.getDocument()));
I see that resulting Map is not sorted by Document.id. Is there a way to do that without add more operation considering that the original List is already sorted?