Menu
Question Index
...

What will be the output of the following program?

import java.util.*;

public class Wonder {
    private enum Gender {
        M, F
    }
    public static void main(String[] args) {
        printSize(new HashMap<Gender, Gender>());
        printSize(new EnumMap<Gender, Gender>(Gender.class));
    }
    private static void printSize(Map<Gender, Gender> map) {
        map.put(Gender.M, Gender.F);
        map.put(Gender.F, Gender.M);
        map.put(Gender.M, Gender.M);
        map.put(Gender.F, Gender.F);
        Set<Map.Entry<Gender, Gender>> set = new HashSet<Map.Entry<Gender, Gender>>(map.entrySet());
        for (Map.Entry<Gender, Gender> e : map.entrySet())
            set.add(new AbstractMap.SimpleEntry<Gender, Gender>(e.getKey(), e.getValue()));
        System.out.print(set.size());
    }
}


12
21
22
Some other output
Compilation Error or Runtime error

Doubts

Problems

Topic: Collection Framework In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App