Java HashSet Methods
All HashSet Methods
A list of all HashSet methods can be found in the table below.
Some methods use the type of the HashSet's items as a parameter or return value. This type will be referred to as T in the table.
| Method | Description | Return Type |
|---|---|---|
| add() | Add an item to the list | boolean|void |
| addAll() | Add a collection of items to the list | boolean |
| clear() | Remove all items from the list | void |
| clone() | Create a copy of the hashset | Object |
| contains() | Checks whether an item exist in the list | boolean |
| isEmpty() | Checks whether the list is empty | boolean |
| iterator() | Return an Iterator object for the HashSet |
Iterator |
| remove() | Remove an item from the list | boolean|T |
| removeAll() | Remove a collection of items from the list | boolean |
| size() | Return the number of items in the list | int |
| spliterator() | Return a Spliterator object for the HashSet |
Spliterator |
| toArray() | Return an array containing the list's items | Object[] |