TreeMap in Java

In the previous post, we have learnt about LinkedHashMap. In this post, we will learn about TreeMap in java.

It has the following features as given below.

  • It implements the NavigableMap interface and extends AbstractMap class.
  • It contains only unique values.
  • It can not have null key but can have multiple null values.
  • It sorts the Map in ascending order.
  • TreeMap is unsynchronized collection class which means it is not suitable for thread-safe operations until unless synchronized explicitly.

Let’s understand this with the Example.

Output:

1–Tablet
2–Desktop
6–TV
10–Laptop
15–Mobile
23–Microphone


Questions/Suggestions
Have any question or suggestion for us?Please feel free to post in Q&A Forum

 

Print Friendly, PDF & Email
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

Leave a Reply

Your email address will not be published. Required fields are marked *