I have this.
private ArrayList<String> words;
It’s a dictionary, so the words are already sorted. By old study I know that a binomial search should be really very very quick, I suppose that Java already implements what is necessary.
So, what is the most efficient way of finding if a certain string exists inside a sorted ArrayList ?
Or should I use a different type?
Thank you.
Try using a
HashSet<String>instead. Its contains method has O(1) lookup assuming that there are not too many hash collisions. From the documentation:A binary search on a sorted
ArrayListis only O(log n). This is still very fast, but it is not as fast as using aHashSet.