The HashSet
provides both O(1) insertion and O(1) search, which is hard to top from a theoretical point of view.
In practice, for a size of 10.000 references, a sorted ArrayList
might still outperform HashSet
, although insertion is O(n) and search is O(log(n)). Why? Because it stores the data (the references at least) in a contiguous memory range and therefore can take advantage of hardware memory caching.
The issue with big-O notation is that it completely ignores the time required for a single operation. That's fine for asymptotic considerations and very huge data sets, but for a size of 10.000 it might be misleading.
Haven't tried it, though. And I bet your Interviewer hasn't either :).