I need a data structure that does contains(element) quickly(preferably O(1)). also it allow me to iterate it in the order it comes in. HashSet satisfy the former, Vector satisfies the latter. does such thing exist in java.util?
2 Answers
Look at the Linked* implementations. They preserve the insert order. In your case you need a LinkedHashSet.