Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class SortedMapExample {
    public static void main(String[] args) {
        SortedMap map = new TreeMap();
        map.put(1, "One");
        map.put(2, "two");
        map.put(3, "Three");
        map.put(4, "Four");
        System.out.println("The head map is: " + map.headMap(3));
        System.out.println("The tail map is: " + map.tailMap(2));
    }
}


The head map is: {1=One, 2=two, 3=Three}
The tail map is: {1=One, 2=two}
The head map is: {1=One, 2=two}
The tail map is: {2=two, 3=Three, 4=Four}
The head map is: {1=One, 2=two, 3=Three}
The tail map is: {2=two, 3=Three, 4=Four}
The head map is: {1=One, 2=two}
The tail map is: {1=One}
Compilation Error or Runtime Error

Doubts

Problems

Topic: TreeMap In Java - java.util.TreeMap

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App