Untitled Document

Subscribe here to get updates on new Videos


29. HashSet?




previous homenext


1. Set is the child interface of Collection.
2. If we want to represent a group of individual objects as a single entity, where duplicates are not allowed and insertion order is not preserved then we should go for Set.
3. Set interface doesn’t contain any new methods. So we have to use only Collection interface methods.


1. The underlying data structure is Hashtable.
2. Duplicates are not allowed. If we are trying to insert duplicates, we won’t get any compiletime or runtime errors. add() method simply returns false.
3. Insertion order is not preserved and all objects will be inserted based n hash-code of objects.
4. Heterogeneous objects are allowed.
5. ‘null’ insertion is possible.
6. implements Serializable and Clonable interfaces but not RandomAccess.
7. HashSet is th best choice, if our frequent operation is Search operation.