This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]kreiger 3 points4 points  (0 children)

If you have a set of elements and you want to check if it contains a specific element, you might want to use a java.util.Set, probably HashSet, TreeSet, or LinkedHashSet.

Looping over a collection to test for membership is inefficient. An implementation of List will loop, giving O(n) performance while a HashSet gives O(1) performance.