Java LinkedHashSet Methods
All LinkedHashSet Methods
A LinkedHashSet stores unique items, like a HashSet. The difference is that a LinkedHashSet keeps the items in the order in which they were added (insertion order). When you print it or loop through it, you get the items in that order.
LinkedHashSet has the same methods as HashSet, and they work the same way, so the links in the table go to the HashSet reference pages.
| Method | Description | Return Type |
|---|---|---|
| add() | Adds an item to the set, if it is not already there | boolean |
| addAll() | Adds all items from a collection to the set | boolean |
| clear() | Removes all items from the set | void |
| clone() | Creates a copy of the set | Object |
| contains() | Checks if an item exists in the set | boolean |
| isEmpty() | Checks if the set is empty | boolean |
| iterator() | Returns an Iterator object, to loop through the items of the set | Iterator |
| remove() | Removes an item from the set | boolean |
| removeAll() | Removes all items that are also in a given collection | boolean |
| size() | Returns the number of items in the set | int |
| spliterator() | Returns a Spliterator object for the set | Spliterator |
| toArray() | Returns an array with all items of the set | Object[] |