Difference beween HashSet and TreeSet ?
Javasearch.buggybread.com

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.
Label / Company      Label / Company / Text

   



Interview Questions and Answers

 Q1. Difference beween HashSet and TreeSet ?Core Java
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


Related Questions

  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 ?

a. HashMap
b. TreeMap
c. LinkedHashMap
d. LinkedMap
  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 ?



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: