Multiple choice

How many constructors of TreeMap are there in Java collections framework?

  1. 6

  2. 5

  3. 4

  4. 3

  5. 2

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

This is the correct answer. There are four constructors of TreeMap. These are:

TreeMap(): It creates an empty Map. TreeMap(Comparator comp): The second form constructs an empty tree-based map that will be sorted by using the Comparator comp. TreeMap(Map m): The third form initialises a tree map with the entries from m, which will be sorted by using the natural order of the keys. TreeMap(SortedMap sm): The fourth form initialises a tree map with the entries from sm, which will be sorted in the same order as sm.