Hi everyone! please help me, how can i get first 5...
# getting-started
s
Hi everyone! please help me, how can i get first 5 elements from from Map<String, Double> ?
j
Maps don't have order. What do you mean by the first 5 elements?
☝🏼 3
☝🏾 1
☝️ 2
s
Copy code
csvService.read(fileList)
.groupBy { it.participant }
.mapValues { (_, challengeRecords) -> challengeRecords.sumOf { it.point } }
.toList()
.sortedByDescending { (k, v) -> v }
.toMap()
i have a sroted map by value, and i need take to first 5 elements
p
You could use
.take(5)
before the
.toMap()
👌🏼 1
👌 1
👌🏻 1
❤️ 1
s
Yes it works! thank you!
m
classic case of https://xyproblem.info/ 😉