This message was deleted.
# getting-started
s
This message was deleted.
s
Strictly speaking, you could still technically “look up” values by keys in the
List<Pair>
structure. It’s a terrible idea but it’s possible.
Copy code
val fred = people.first { it.first = "a" }.second
It’s really the only reason I’d consider the two constructs even comparable for this kind of question 😕
I mean, you and I understand that, but to a lot of people it’ll achieve the goal they’ve set. I put
"look up"
in quotes for a good reason - you’re right that the difference is very important. I just don’t know why else someone would compare the two.
Edited my example to be more in line with your snippet, to show a naive “key-based lookup”, heavy on the quotation marks lol
f
Thanks guys. The sample using first {} is obscure to me but actually the difference is pretty clear and I wonder why I got confused. Probably because the use of the same "to", function, although it yielded significantly different results according to the case.
a
also, note that the list can contain the same "key" more than once and has order, not all maps guarantee to maintain their items sequence order.
✔️ 3
a
@febs note that the
mapOf
function takes
vararg of pairs
to construct a map - perhaps that's where the confusion stems from? 🙂
👍 1
Definition:
fun <K, V> mapOf(vararg pairs: Pair<K, V>): Map<K, V>