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 the SimpleTimeZone class?

1882


What is the main purpose of serialization in java?

637


What is runtime polymorphism or dynamic method dispatch?

624


What methods are used to get and set the text label displayed by a button object?

645


What is port number in java?

691






What methodology can be utilized to link to a database?

596


Is java written in c?

633


Why is string class considered immutable?

691


Explain the importance of throws keyword in java?

656


In the below example, what will be the output?

675


Write code to implement bubble sort in java?

642


How do you square a number in java?

665


What is the difference between static and global variables and also define what are volatile variables?

663


Hi friends am new to java. I read jar file means collection of java files. For executing struts application what are the necessary jar files. " struts.jar " file contains what. can u explain

1548


Can java arraylist hold different types?

607