Java – How to get size of HashMap

Size of HashMap can be find by size() method. In size method, it will return value in integer.

Example of finding size in HashMap in Java

HashMap<Object,String> hm=new HashMap<Object,String>();

hm.put(new Integer(2), "Two");
hm.put(new Integer(1), "One");
hm.put(new Integer(3), "Three");
hm.put(new Integer(4), "Four");

int sizeOfHashMap=hm.size();

System.out.println("Size of HashMap :"+sizeOfHashMap);

Output

Size of HashMap :4

Tags:

Bookmark  

 

Leave a Reply

Security Code:

 

  Random Post