java - Data structure with O(1) performance for get(int index) and ability to avoid duplication -



java - Data structure with O(1) performance for get(int index) and ability to avoid duplication -

set obvious choice, if not want have duplication on list of data.

however, set doesn't have get(int index) method : why doesn't java.util.set have get(int index)?

several suggestions implement pseudo get(int index) , none of them efficient.

toarray , access new array index. get iterator, , utilize for loop access indexed element count.

is there advanced info structure, enables me to

avoid duplication. have o(1) performance get(int index).

the simplest approach have composite collection contains hashset , arraylist. add operation seek add together set, , add together list if has added new item. get operation list.

do ever need remove values? if not, makes life simpler - otherwise, removing item o(n) operation. not problem, bear in mind.

java data-structures

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -