Reputation: 523
I have a very large collection which contains more than a million String elements. It is very often to check whether a coming String is in this collection or not.
I wonder which collection is better to use, List or Set? And why?
Upvotes: 2
Views: 3477
Reputation: 9320
Set will be more fast, since it could be based on tree structure (complexity will be something like O(height of the tree) or using hashes (complexity will be near O(const)) , on the other size contains for List will have complexity O(n), where n - size of the list
So Set should be faster when we talk about large calls of contains()
Upvotes: 9