2

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 2

9

LinkedHashSet?

Sign up to request clarification or add additional context in comments.

Comments

2

Look at the Linked* implementations. They preserve the insert order. In your case you need a LinkedHashSet.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.