Set
is an obvious choice, if I do not want to have duplication on my list of data.
However, Set
doesn't have get(int index)
method : Why doesn't java.util.Set have get(int index)?
Several suggestions to implement a pseudo get(int index)
and none of them are efficient.
toArray
and access the new array by index.- Get the iterator, and use a
for
loop to access the indexed element by count.
Is there any advanced data structure, which enables me to
- Avoid duplication.
- Have O(1) performance for
get(int index)
.