Explain the difference between treeset and treemap in java?



Explain the difference between treeset and treemap in java?..

Answer / Randhir Pratap

In Java, TreeSet and TreeMap are both sorted collections. However, they differ in their implementation and capabilities:
1. TreeSet stores elements in a sorted order based on their natural ordering or a custom comparator.
2. TreeMap stores key-value pairs in a sorted order based on the keys.
3. TreeSet does not allow duplicate elements.
4. TreeMap allows duplicate keys, but they will overwrite the existing value.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

Difference between collection, collection and collections in java?

1 Answers  


What is the driver class?

1 Answers  


What is jit and its use?

1 Answers  


What is the difference between static method and instance method in Java?

1 Answers   SwanSoft Technologies,


How to print nodes of a Binary tree?

1 Answers   TCS,


Differentiate between class and structure.

1 Answers   Amdocs, Motorola,


1) There are 10 different threads in runnable state. Each having priority 1 to 10. How does the CPU schedules or executes these threads?

2 Answers   RBS,


What are data types in programming?

1 Answers  


what is difference between front controller and action servlet?

2 Answers  


What is number data type in java?

1 Answers  


Is void a return type?

1 Answers  


What is the range of a character variable?

1 Answers  


Categories