Any big difference between using contains or loop through a list?
Posted
by Nazgulled
on Stack Overflow
See other posts from Stack Overflow
or by Nazgulled
Published on 2010-05-21T21:53:46Z
Indexed on
2010/05/21
22:00 UTC
Read the original article
Hit count: 229
Hi,
Performance wise, is there really a big difference between using:
- ArrayList.contains(o) vs foreach|iterator
- LinkedList.contains(o) vs foreach|iterator
- HashMap.(containsKey|containsValue) vs foreach|iterator
- TreeMap.(containsKey|containsValue) 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.
© Stack Overflow or respective owner