LinkedHashSet class implements an efficient abstraction for storing sets of values.
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
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.
LinkedHashSet provides identical lookup (
contains) speed, nearly the same insertion (
add) speed, and slower removal (
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.