Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
import java.util.Map.*;

public class HashTable
{
    public static void main(String args[])
    {
        Hashtable<String, String> hashtable = new Hashtable<String, String>();
        hashtable.put("first", "1");
        hashtable.put("second", "2");
        hashtable.put("third", "3");
        hashtable.put("third", "3");
        hashtable.put("five", "5");
        hashtable.put("six", "5");

        List<String> list = new ArrayList<String>(hashtable.keySet());
        Collections.sort(list);

        for(String key : list)
        {
            System.out.println(key + " -> " + hashtable.get(key));
        }
    }
}


first -> 1
second -> 2
third -> 3
six -> 5
first -> 1
five -> 5
second -> 2
six -> 5
third -> 3
third -> 3
first -> 1
five -> 5
second -> 2
six -> 5
third -> 3
first -> 1
second -> 2
third -> 3
third -> 3
five -> 5
six -> 5
Compilation Error  or Runtime Error

Doubts

Problems

Topic: Java Hashtable

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App