Home » JAVA Programming » Collections » Question
  1. What is the output of this program?
    import java.util.*;
    public class Map_Example
    {
    public static void main(String args[])
    {
    HashMap object = new HashMap();
    object.put("D", new Integer(4));
    object.put("E", new Integer(5));
    object.put("F", new Integer(6));
    System.out.println(object.keySet());
    }
    }
    1. {D=4, E=5, F=6}
    2. [D, E, F]
    3. [D, E, F] 3
    4. [D=4, E=5, F=6]
    5. None of these
Correct Option: B

keySet() method returns a set containing all the keys used in the invoking map. Here keys are characters D, E & F. 4, 5, 6 are the values given to these keys.



Your comments will be displayed only after manual approval.