https://kotlinlang.org logo
Title
v

Varun

03/19/2021, 3:11 PM
hey really rookie question. If i have a mutable map = {3=0, 4=0, 5=0, 6=0, 7=1, 8=1, 9=1, 10=1, 11=2} . If I'm trying to get the max value in this --map.maxBy{it.value} . It returns a value 11=2. What type is this and how do I get the value "2" from it? -> https://leetcode.com/playground/eQrqK2Ug
1
w

wbertan

03/19/2021, 3:15 PM
Hey @Varun, it would be of type
Map.Entry<Int, Int>
You can access by the properties
key
and `value`:
println(maxi.key) // 11
        println(maxi.value) // 2
v

Varun

03/19/2021, 3:32 PM
Hey @wbertan thanks! I swear i tried that 10 times... but somehow works now :S
Line 5: Char 17: error: unresolved reference: value println(maxi.value)
did you change anything in that leetcode thing?
w

wbertan

03/19/2021, 3:33 PM
Nope, copied your code into Android Studio to see
a

araqnid

03/19/2021, 3:37 PM
or you can use
cache.values.max()
if you don’t care about the keys at all
v

Varun

03/19/2021, 3:38 PM
thanks @araqnid