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

How do you change an int to a string?

728


What is your platform’s default character encoding?

751


What is token in java?

750


How does regex work?

711


What is a for loop in java?

796






What is the static method?

721


what is optional in java 8?

789


When would you use a static class?

729


What is identifier give example?

759


Which browsers work with java?

788


Realized?

1871


Is null a value?

761


What is the difference between hashmap and hashtable? What is an interface?

749


Can we create a constructor in abstract class?

738


How do you use equal in java?

716