Map map = new HashMap(2);
map.add(“1”,”one”);
map.add(“2”,”two”);
map.add(“3”,”three”); What will happen at this line?

Answer Posted / sreekanth madamanchi

We don't have a method add() in HashMap.
We have put().
Map map = new HashMap(2);
map.put("1","one");
map.put("2","two");
map.put("3","three");
System.out.println("Size of the map="+map.size());

If we wrote like this, it will extend the size.
The out put is: Size of the map=3

Is This Answer Correct ?    18 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is += mean in java?

547


Can two objects have same hashcode?

566


What is a class in java?

582


What is the difference between the paint() and repaint() methods in java programming?

635


What is method and methodology?

608






Give some features of interface?

587


What is getkey () in java?

581


Differentiate between the constructors and methods in java?

511


What is the difference between private & public & friendly classes?

554


Why webdriver is an interface?

587


What is the difference between stringbuffer and stringbuilder class?

578


What is the difference between multitasking and multithreading in Java

728


If two threads have same priority which thread will be executed first ?

846


What about static nested classes in java?

592


Explain the difference between jdk, jre, and jvm?

596