Search Interview Questions
| More than 3000 questions in repository.|
There are more than 900 unanswered questions.
Click here and help us by providing the answer.
Have a video suggestion.
Click Correct / Improve and please let us know.
|Interview Questions and Answers|
|Ans. 1. HashSet doesnt maintain its elements in any specific order and is all random whereas TreeSet maintains elements in natural order 9 order defined by the equals method of TreeSet element type )|
2. TreeSet doesnt allow null elements whereas HashMap does.
3. As TreeSet orders elements and is hence insertion is comparatively slower.
4. HashSet performs basic operations like add(), remove(), contains(), size() etc. in a constant size time. A TreeSet performs these operations at the order of log(n) time.
5. HashMap in Java internally backs a HashSet. A NavigableMap backs a TreeSet internally.
|Help us improve. Please let us know the company, where you were asked this question :|
|Like Discuss Correct / Improve  collections  hashset  treeset  set   hashet vs treeset Asked in 4 Companies Basic   frequent|
Try 1 Question(s) Test
|Difference between TreeMap and HashMap ?|
|What is reflection ?|
|What is comparator interface used for ?|
|If I try to add Enum constants to a TreeSet, What sorting order will it use ?|
| Which of the following collections stores its elements in insertion Order ? |
|Which are the sorted collections ?|
|Which of the following collection maintain its elements in Natural Sorted order ?|
|What is a binary tree ?|
|What are the phases of the JSP life cycle ?|