In particular: how to get the nth element of LinkedHashSet (which has a predictable iteration order)? I want to get the nth element inserted in this Set(which has not been present yet).
Is it better to use List:
List<T> list = new ArrayList<T>(mySet);
T value = list.get(x);
or toArray(T [] a):
T [] array = mySet.toArray(new T[mySet.size()]);
T value = array[y];
Besides the (albeit minor) differences in performance, all that needs to be tracked? Any clear winner?
Change 1
NB: It doesn't matter why I need the last inserted element, all that matters is what I want. The LinkedHashSet was specifically chosen because it "determines the iteration order, which is the order in which the elements were inserted into the set (insertion order). Note that the insertion order does not change if the element is reinserted into the set."
Edit 2
This question seems to have moved on to discuss whether any implementation will be able to Setmaintain the original insertion order. So I put a few simple test codes in http://pastebin.com/KZJ3ETx9 to show that yes, LinkedHashSet really keeps the insertion order (the same as its iteration order) as its Javadok claims.
Edit 3
, Set ( , , , ).