I have an object Batch (String id, Instant date, Long version)
I have a list of Batch and I want to filter to keep one batch for each id where version is the highest i.e:
batch1 = Batch(1, date, 5)
batch2 = Batch(2, date, 4)
batch3 = Batch(2, date, 7)
batch4 = Batch(1, date, 2)
batch5 = Batch(1, date, 4)
batch6 = Batch(3, date, 2)
after filtering I need to have
List.of(batch1, batch3, batch6)```
You can use stream with toMap like this:
Outputs
If you want to get List instead of Collection, you can simply use: