A LinkedHashSet is a hash-table based Set implementation.
The LinkedHashSet
also keep track of the order that elements were inserted
in, and iteration happens in first-to-last insertion order.
The elements of a LinkedHashSet
must have consistent Object.operator==
and Object.hashCode implementations. This means that the ==
operator
must define a stable equivalence relation on the elements (reflexive,
symmetric, transitive, and consistent over time), and that hashCode
must be the same for objects that are considered equal by ==
.
The set allows null
as an element.
Iteration of elements is done in element insertion order. An element that was added after another will occur later in the iteration. Adding an element that is already in the set does not change its position in the iteration order, but removing an element and adding it again, will make it the last element of an iteration.
Most simple operations on HashSet
are done in (potentially amortized)
constant time: add, contains, remove, and length, provided the hash
codes of objects are well distributed..