Menu
Question Index
...

What will be the output of the following program?

import java.util.*;

public class DemoOnMaps {
    public static void main(String args[]) {
        Map<Planning, String> objects = new HashMap<Planning, String>();
        Planning planning1 = new Planning("Monday");
        Planning planning2 = new Planning("Tuesday");
        Planning planning3 = new Planning("Tuesday");
        objects.put(planning1, "Reading");
        objects.put(planning2, "Dancing");
        objects.put(planning3, "Drawing");
        System.out.println("Size :" + objects.size());
    }
}

class Planning {
    String day;
    public Planning(String today) {
        day = today;
    }
    public boolean equals(Object object) {
        return ((Planning) object).equals(day);
    }
}


Size :3
Size :2
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java HashMap Implementation

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App