Skip to content
Advertisement

How to remove from list if list based on condition

I have a list of objects like this:

JavaScript

I want to iterate the list and only keeps the objects where the dates differ. If there are two objects with the same date then I want to keep the object with the bigger value. Can this be achieved by using streams and predicates somehow?

Advertisement

Answer

You should use Map and Map.merge() instread of Stream.

JavaScript

output:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement