HashSet
- The underlying Data Structure for HashSet is Hashtable.
- Insertion order is not preserved and it is based on has code of the Object.
- Duplicate objects are not allowed. Violation leads to no Compile Time Error or RuntimeError, add method simply returns false.
- ‘null’ insertion is possible.
- Heterogeneous objects are allowed.
- HashSet is the best choice if the frequent operation is Search Operation.
TreeSet
- The underlying Data structure for the TreeSet is Balanced tree.
- Duplicate objects are not allowed. If we are trying to insert duplicate object we won’t get any compile time error or Run time error, add method simply returns false.
- Insertion order is not preserved but all the elements are inserted according to some sorting order.
- ‘null’ insertion is not possible.
- Heterogeneous objects are not allowed, violation leads to Run time error saying class cast Exception.
No comments:
Post a Comment