Performance wise, is there really a big difference between using:
- ArrayList.contains(o) vs foreach|iterator
- LinkedList.contains(o) vs foreach|iterator
Of course, for the foreach|iterator loops, I’ll have to explicitly compare the methods and return true or false accordingly.
The object I’m comparing is an object where equals() and hashcode() are both properly overridden.
EDIT: Don’t need to know about containsValue after all, sorry about that. And yes, I’m stupid… I realized how stupid my question was about containsKey vs foreach, nevermind about that, I don’t know what I was thinking. I basically want to know about the ones above (edited out the others).
EDITED:
With the new form of the question no longer including HashMap and TreeMap, my answer is entirely different. I now say no.
I’m sure that other people have answered this, but in both LinkedList and ArrayList, contains() just calls indexOf(), which iterates over the collection.
It’s possible that there are tiny performance differences, both between LinkedList and ArrayList, and between contains and foreach, there aren’t any big differences.