posted 16 years ago
I have seen this question:
Which of the following classes, will return elements in the order they were added (first in first out) when accessed via an iterator?
1 java.util.HashSet
2 java.util.Vector
3 java.util.LinkedHashSet
4 java.util.TreeSet
I thought the answer was 3, but the correct answer is 2 and 3. This made me wonder why, and I think that it must be like this that all lists (ArrayList, Vector and LinkedList) return elements in the added order, since they are indexed listed, and the linked collections (LinkedList, LinkedHashSet, LinkedHashMap) return them in the added order because they are linked. The other collections return them in a sorted order, TreeSet for example, or in a random order, like for example HashSet.
Is that correct?
[ August 04, 2007: Message edited by: Marc Wentink ]