https://kotlinlang.org logo
#announcements
Title
# announcements
a

Alexjok

06/21/2019, 7:57 AM
I have case where i need to find all duplicates in list by code and finally get values from duplicateList with lower dateTime. Any ideas?
Copy code
fun main() {
      val fileList = listOf<FileName>()
}

data class FileName(val code: String, val uid: String, val dateTime: LocalDateTime)
d

diesieben07

06/21/2019, 8:07 AM
a

Alexjok

06/21/2019, 8:08 AM
I need to do the opposite, get only duplicate codes 🙂
d

diesieben07

06/21/2019, 8:10 AM
Copy code
list.groupingBy { it.key }
  .eachCount()
  .filterValues { it > 1 }
👍 1
that gives you all the duplicate keys as keys in the map. You can do
.keys
if you need them as a separate collection
a

Alexjok

06/21/2019, 8:12 AM
yes that's exactly what i want! Thx
2 Views