What is the difference between HashSet and TreeSet in Java?
HashSet | TreeSet | |
---|---|---|
1. | Offers constant time cost | Offers log time cost |
2. | Does not maintain the order of elements | By default sorts elements in ascending order. |
3. | Implemented using a hash table | Implemented using Binary Search Tree |
BY Best Interview Question ON 13 Jan 2019