What will be the output of the following Java program? [code] import java.util.*; class Maps { public static void

Huyền Thu

New member
What will be the output of the following Java program?
Code:
    import java.util.*;
    class Maps 
    {
        public static void main(String args[]) 
        {
            HashMap obj = new HashMap();
            obj.put("A", new Integer(1));
            obj.put("B", new Integer(2));
            obj.put("C", new Integer(3));
            System.out.println(obj.keySet());
        }
    }
A. [A, B, C]
B. {A, B, C}
C. {1, 2, 3}
D. [1, 2, 3]
 
Answer: a
Explanation: keySet() method returns a set containing all the keys used in the invoking map. Here keys are characters A, B & C. 1, 2, 3 are the values given to these keys.
Output:
Code:
$ javac Maps.java
$ java Maps 
[A, B, C].
 

Tìm kiếm

Back
Top