user157195
user157195

Reputation:

java collections data structure

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?

Upvotes: 2

Views: 321

Answers (2)

Petar Minchev
Petar Minchev

Reputation: 47373

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

Upvotes: 2

Stan Kurilin
Stan Kurilin

Reputation: 15792

LinkedHashSet?

Upvotes: 9

Related Questions