I wonder which is faster between list.contains() and set.contains() in scala

collections, scala

Solution

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()

Problem

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?

Original source