What is the difference between hashset and treeset in java?



What is the difference between hashset and treeset in java?..

Answer / Abhinaya Bhullar

{"hashset": "An implementation of the Set interface that allows null elements. HashSet does not guarantee the order of its elements, nor does it maintain any order.","treeset": "A sorted set that stores its elements in a red-black tree, which is self-balancing binary search tree that provides guaranteed log(n) time complexity for basic operations like add, remove, and contains.","difference": "HashSet does not guarantee the order of its elements, while TreeSet maintains a sorted order of its elements. HashSet allows null elements whereas TreeSet does not allow duplicate null elements."}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

waht You know about thread programming?

1 Answers  


What is constructor and virtual function? Can we call a virtual function in a constructor?

1 Answers  


What is the default execution method in java?

1 Answers  


Enlist few advantages of inheritance?

1 Answers  


Is main a function?

1 Answers  


In Java list the methods that can be overridden?

1 Answers   Accenture,


What is difference between Iterator and for loop

9 Answers   HP,


What do you understand by the bean persistent property?

1 Answers  


what is method reference in java 8?

1 Answers  


What is difference between final and finally in java?

1 Answers   Cyient,


What are the common uses of "this" keyword in java ?

1 Answers  


What is the use of join method?

1 Answers  


Categories