hej! Any good way to make a set from List<T>...
# announcements
k
hej! Any good way to make a set from List<T> by checking only one property? smth like
Copy code
val customersSet = customers.collectToSet { it.phoneNumber }
which will make a set of customers with non-repeating phone numbers
m
You can do
customers.distinctBy { it.phoneNumber }
, but it will return a
List
. You can do
toSet
after to make it a set.
🎉 1
k
exactly what i needed, thank you a lot 🙂
m
No problem 🙂
r
Not sure if that is correct way
âž• 1
you want Set<Customer> in the end?
Nvm, while Customer has proper
equals
checks then it should be fine