Is it even possible?
Say you have
private Set names = new LinkedHashSet();
and Strings ar
A Set is "a collection that contains no duplicate elements," and it does not maintain order of its elements. http://download.oracle.com/javase/6/docs/api/java/util/Set.html
The code you have given will not necessarily return 1 every time. Iterating through a Set is not guaranteed to iterate in the same order every time; it is only guaranteed to iterate over each element once.
Since you seem to care about the order of the elements, you need to be using a List instead of a Set.
It is generally not possible for a Set to return the index because it's not necessarily well defined for the particular Set implementation. For example it says in the HashSet documentation
It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.
So you shouldn't say the type is Set when what you actually expect is a Set implementing som order.