Menu
Topics Index
...
`

Add items to Dictionary and printing


If you need explanation Read this topic

If you need Answer Take test on this topic

Add items to Dictionary and printing
What will be the output of the following program?
import java.util.*;
public class TouchMe {
    public static void main(String[] args) {
        Dictionary d = new Hashtable();
        d.put("1", "Apple");
        d.put("2", "Samsung");
        d.put("3", "Sony");
        d.put("4", "Nokia");
        d.put("5", "Karbon");
        d.put("6", "Micro Max");
        for (int i = 1; i <= d.size(); i++) {
            System.out.print(d.get("" + i) + ", ");
        }
    }
}

A. Micro Max, Karbon, Nokia, Sony, Samsung, Apple,
B. Apple, Samsung, Sony, Nokia, Karbon, Micro Max,
C. Some other output
D. Output can not be determined
E. Compilation Error or Runtime Error
Topic: Java Dictionary Class - java.util.Dictionary

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 B,
Hash table stores values at particular keys, Here all six are storing in a sequence and the same order is printed.

Posted by Amar Kumar Biradar    2014-01-13 04:48:25


Congratulations Amar Kumar Biradar. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-01-14 07:41:39


Thanks Merit Campus ;)
Got Recharge :)

Posted by Amar Kumar Biradar    2014-01-15 04:45:31


© meritcampus 2019

All Rights Reserved.

Open In App