LinkedHashSet
implements the Set
interface. The contract for Set
does not require implementations to keep the items in any particular order. As a result, Set
does not have methods such as indexOf(Object object)
or get(int index)
. As it happens, a LinkedHashSet
does keep the elements in order (insertion order), but this does not mean you can conveniently access the item at a particular index or find the index of an item. It just means that when you iterate over the entire Set
, the order will be insertion order.
While your question is not entirely clear, it sounds like you should be using a List
rather than a Set
. Unless you have a very good reason you should use the most common implementation of List
which is ArrayList
. To find the index of an item in a List
do list.indexOf(item);