Q:

How I can delete duplicates in a Object list by date in Kotlin with collection operators?

I have a object list with the same id, then, i want to keep the one with the most recent date, and the delete the other with the kotlin collection operators. For Example I have :
{"id":111,
 "date":"02/12/2017"
 }

and the other
{"id":111,
 "date":"02/8/2018"}

In this case, i would like to delete the first object.

A:

You can achieve it like this 
list.groupBy { it.id }.entries.map { it.value.maxBy { it.date } }

it will create a map of id, List<object> while keeping original order and then choose newest object from the list. 
Here I am assuming date is long value timestamp

A:

If you really must remove the entries from the current collection the following may help you (I assume your objects (Obj) are contained in a list called list):
list.removeAll { anObj -> list.any { anObj.id == it.id && it.date > anObj.date } }
// or same with removeIf

It's probably easier just collecting what you are actually interested in and then have an immutable list in the first place.
Collecting the elements you are interested in could be done as follows (there are of course lots of other ways to do that... just one of many):
val result = list.groupBy { it.id }.values.mapNotNull { it.maxBy { it.date } } // mapNotNull is only used due to maxBy returning a nullable type... it isn't really needed... or well... depends on what your date type is ;-)

result will then be a List<Obj>. Instead of mapNotNull you could also use it.maxBy { it.date }!! if you know there is at least 1 element.
If you then still need to remove the elements from the list, you could do the following:
list.removeIf { it !in result }
// or
list.removeAll { it !in result }

However I can't really recommend that you mutate your current list just for that... The result in the above example already contains all the elements in the form you want (i.e. List<Obj>). Instead rather use the benefit of having an immutable list :-)

