When do we use hashset over treeset?



When do we use hashset over treeset?..

Answer / Shantanu Shukla

We use HashSet instead of TreeSet when the order of elements does not matter and performance is a concern, as HashSet has faster insertion and retrieval times compared to TreeSet due to its lack of ordering. However, if maintaining the order of elements (either ascending or descending based on natural ordering or custom Comparator) is important, we should use TreeSet.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

How do you use spaces in java?

1 Answers  


What are kinds of processors?

1 Answers  


What is the difference between equals() and == in java?

0 Answers  


Why is stringbuffer thread safe?

1 Answers  


What is the difference between the jdk 1.02 event model and the event-delegation model introduced with jdk 1.1?

1 Answers  


How do you set security in applets?

1 Answers   Wipro,


How do you remove an element from an arraylist in java?

1 Answers  


what is the difference b/w static and final methods?

1 Answers  


we have two threads..both the threads are reading the data.. is there any need of synchronization there?...justify it?

4 Answers   IBM,


what is optional in java 8?

1 Answers  


What are jee technologies?

1 Answers  


What is the return type of read()?

3 Answers  


Categories