class LinkedHashSet<ValueType>
The LinkedHashSet
class implements an efficient abstraction for storing sets of values.
A LinkedHashSet
is the same as a HashSet
, except that it exposes its values in the order they were inserted, rather than in the unpredictable order of a standard HashSet
.
This is accomplished by storing the data in two ways internally: (1) in a hash table array, as in a HashSet
; and (2) in a linear list, to remember the insertion order.
A LinkedHashSet
provides identical lookup (contains
) speed, nearly the same insertion (add
) speed, and slower removal (remove
) speed.
Its for-each loop and iterators emit the elements in the order they were added to the set, at the cost of the additional memory usage of the internal list.
Since the members of LinkedHashSet
are the same as those of HashSet
, in the interest of avoiding redundancy, we refer you to the HashSet
documentation for descriptions of each member.