- Java.util - WeakHashMap
- Java.util - Vector
- Java.util - UUID
- Java.util - TreeSet
- Java.util - TreeMap
- Java.util - TimeZone
- Java.util - TimerTask
- Java.util - Timer
- Java.util - StringTokenizer
- Java.util - Stack
- Java.util - SimpleTimeZone
- Java.util - ServiceLoader
- Java.util - Scanner
- Java.util - ResourceBundle.Control
- Java.util - ResourceBundle
- Java.util - Random
- Java.util - PropertyResourceBundle
- Java.util - PropertyPermission
- Java.util - Properties
- Java.util - PriorityQueue
- Java.util - Observable
- Java.util - Locale
- Java.util - ListResourceBundle
- Java.util - LinkedList
- Java.util - LinkedHashSet
- Java.util - LinkedHashMap
- Java.util - IdentityHashMap
- Java.util - Hashtable
- Java.util - HashSet
- Java.util - HashMap
- Java.util - GregorianCalendar
- Java.util - Formatter
- Java.util - EnumSet
- Java.util - EnumMap
- Java.util - Dictionary
- Java.util - Date
- Java.util - Currency
- Java.util - Collections
- Java.util - Calendar
- Java.util - BitSet
- Java.util - Arrays
- Java.util - ArrayList
- Java.util - ArrayDeque
- Java.util - Home
Java.util Package Extras
- Java.util - Discussion
- Java.util - Useful Resources
- Java.util - Enumerations
- Java.util - Exceptions
- Java.util - Interfaces
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java.util.HashSet Class
Introduction
The java.util.HashSet class implements the Set interface, backed by a hash table.Following are the important points about HashSet −
This class makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.
This class permits the null element.
Class declaration
Following is the declaration for java.util.HashSet class −
pubpc class HashSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, Seriapzable
Parameters
Following is the parameter for java.util.HashSet class −
E − This is the type of elements maintained by this set.
Class constructors
Sr.No. | Constructor & Description |
---|---|
1 | HashSet() This constructs a new, empty set; the backing HashMap instance has default initial capacity (16) and load factor (0.75). |
2 | HashSet(Collection<? extends E> c) This constructs a new set containing the elements in the specified collection. |
3 | HashSet(int initialCapacity) This constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor (0.75). |
4 | HashSet(int initialCapacity, float loadFactor) This constructs a new, empty set; the backing HashMap instance has the specified initial capacity and the specified load factor. |
Class methods
Sr.No. | Method & Description |
---|---|
1 | This method adds the specified element to this set if it is not already present. |
2 | This method removes all of the elements from this set. |
3 | This method returns a shallow copy of this HashSet instance, the elements themselves are not cloned. |
4 | This method returns true if this set contains the specified element. |
5 | This method returns true if this set contains no elements. |
6 | This method returns an iterator over the elements in this set. |
7 | This method removes the specified element from this set if it is present. |
8 | This method returns returns the number of elements in this set(its cardinapty). |
Methods inherited
This class inherits methods from the following classes −
java.util.AbstractSet
java.util.AbstractCollection
java.util.Object
java.util.Set