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

Answers were Sorted based on User's Feedback



Map map = new HashMap(2); map.add(“1”,”one”); map.add(“2”,”two”); map.add(“3”..

Answer / haneef

see, there is no add() in the Map, so u will get compilation
error.

there is only put();

Is This Answer Correct ?    22 Yes 0 No

Map map = new HashMap(2); map.add(“1”,”one”); map.add(“2”,”two”); map.add(“3”..

Answer / 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

Map map = new HashMap(2); map.add(“1”,”one”); map.add(“2”,”two”); map.add(“3”..

Answer / zzzz

Unresolved compilation error will come.

Is This Answer Correct ?    1 Yes 0 No

Map map = new HashMap(2); map.add(“1”,”one”); map.add(“2”,”two”); map.add(“3”..

Answer / mallu

No error will be generaterd.

Is This Answer Correct ?    3 Yes 8 No

Map map = new HashMap(2); map.add(“1”,”one”); map.add(“2”,”two”); map.add(“3”..

Answer / raman t

if we write like this then it would be better.


HashMap map = new HashMap();
map.add( "cat", "Meow" );
map.add( "ape", "Squeak" );
map.add( "dog", "Woof" );
map.add( "bat", "Squeak" );
System.out.println( "map = " + map );

Is This Answer Correct ?    2 Yes 14 No

Post New Answer

More Core Java Interview Questions

What is threaded programming and when is it used? : Java thread

0 Answers  


WHAT IS THE MEANING OF ALL TYPE OF BUZZWORDS?

4 Answers  


Which class should you use to obtain design information about an object in java programming?

0 Answers  


List some important features of java 10 release?

0 Answers  


Name few "optional" classes introduced with java 8 ?

0 Answers  






How many times garbage collector will invoke an object?s finalize() method?

4 Answers  


Is void a keyword in java?

0 Answers  


Can we overload the methods by making them static?

0 Answers  


How is a structure different from array ?

0 Answers   Amdocs,


public class Base { public void myMethod(int a,intb) {} } // Uses myMethod and then hides it. public class DerivedOne extends Base { private void myMethod(int a,int b); } will this compile or not .yes or no. why

2 Answers  


What happens when I use / and % with a negative numerator?

0 Answers  


When is the finally clause of a try-catch-finally statement executed?

0 Answers  


Categories