Menu
Topics Index
...
`

Months


If you need explanation Read this topic

If you need Answer Take test on this topic

Months
What will be the output of the following program?
import java.util.*;
public class Months {
    public static void main(String args[]) {
        SortedMap map = new TreeMap();
        map.put("January", 1);
        map.put("March", 3);
        map.put("June", 6);
        map.put("August", 8);
        Iterator it = map.keySet().iterator();
        while (it.hasNext()) {
            Object key = it.next();
            System.out.print(key + "-" + map.get(key) + ", ");
        }
    }
}

A. January-1, March-3, June-6, August-8,
B. August-8, June-6, March-3, January-1,
C. August-8, January-1, June-6, March-3,
D. January-1, June-6, March-3, August-8,
E. Compilation Error or Runtime Error  
Topic: TreeMap In Java - java.util.TreeMap

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Answer is c since The sorted map orders according to the natural ordering of its keys,

Posted by Shashanka Mogaliraju    2014-08-13 10:47:32


c

Posted by Zeg Abder    2014-08-13 11:09:15


c

Posted by Deepika Deepu    2014-08-13 15:40:25


Congratulations Shashanka Mogaliraju. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-14 04:13:57


© meritcampus 2019

All Rights Reserved.

Open In App