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 |
Difference between collection, collection and collections in java?
What is the driver class?
What is jit and its use?
What is the difference between static method and instance method in Java?
1 Answers SwanSoft Technologies,
How to print nodes of a Binary tree?
Differentiate between class and structure.
1) There are 10 different threads in runnable state. Each having priority 1 to 10. How does the CPU schedules or executes these threads?
What are data types in programming?
what is difference between front controller and action servlet?
What is number data type in java?
Is void a return type?
What is the range of a character variable?