Java OCA OCP Practice Question 1619

Question

What is the output of the following?

TreeMap<String, Integer> map = new TreeMap<>();
map.put("3", 3);
map.put("three", 3);
map.put("THREE", 3);
System.out.println(map.firstKey() + " " + map.lastKey());
  • A. 3 three
  • B. 3 THREE
  • C. three 3
  • D. THREE 3


A.

Note

Unfortunately you do have to memorize two facts about sort order.

First, numbers sort before letters.

Second, uppercase sorts before lowercase.

Since TreeMap orders by key, the first key is 3 and the last is three, making Option A correct.




PreviousNext

Related