Given:
import java.util.NavigableMap; import java.util.TreeMap; public class Main { public static void main(String[] args) { TreeMap<String, String> m1 = new TreeMap<String, String>(); m1.put("a", "amy"); m1.put("f", "frank"); NavigableMap<String, String> m2 = m1.descendingMap(); try {/* w ww . jav a2s .c o m*/ m1.put("j", "john"); m2.put("m", "mary"); } catch (Exception e) { System.out.print("ex "); } m1.pollFirstEntry(); System.out.println(m1 + "\n" + m2); } }
What is the result?
D is correct.
The descendingMap()
method creates a NavigableMap in reverse order, which is "backed" to the map it was created from.
It is NOT a subMap
, so there is no worry about being outside of its range.
The pollFirstEntry()
method returns AND removes the "first" entry in the Map.