https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

Andrea Giuliano

06/02/2021, 8:35 AM
Hi guys, given a mutableSet, I’d like to remove all the items from a collection, and then just get X items from it. For example
Copy code
myMutableSet.removeAll(collection)
myMutableSet.take(x)
now I’d like not to use take since the set can contain millions of items and I’d like not to copy all in a new set..any suggestions? There is no constraints on the “which” X items to take..random is fine
alternatively, I’ll be happy to move the set into a list, as long as the items won’t be copied..
u

Ulrik Rasmussen

06/02/2021, 11:19 AM
The items themselves will not be copied, only their references, so if that satisfies your constraints, then the code above is fine
3 Views