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 set | boolean |
| addAll() | Add a collection of items to the set | boolean |
| clear() | Remove all items from the set | void |
| clone() | Create a copy of the set | Object |
| contains() | Check whether an item exists in the set | boolean |
| isEmpty() | Check whether the set is empty | boolean |
| iterator() | Return an Iterator object for the HashSet |
Iterator |
| remove() | Remove an item from the set | boolean |
| removeAll() | Remove a collection of items from the set | boolean |
| size() | Return the number of items in the set | int |
| spliterator() | Return a Spliterator object for the HashSet |
Spliterator |
| toArray() | Return an array containing the set's items | Object[] |