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 many bytes is a string?

562


What are 3 boolean operators?

535


Explain importance of inheritance in java?

604


What ide should I use for java?

492


What is hash table in java?

494






Discuss 2D arrays.

610


Write a program to check for a prime number in java?

560


What are the uses of java?

571


What is floating data type?

539


Name few java 8 annotations ?

565


Why collection is called framework in java?

540


What is thread safe singleton?

517


What is incompatible types in java?

539


What is the synonym of procedure?

531


What is oop principle in java?

547