Size of Map can be find by size() method. In size method, it will return value in integer.
Example of finding size in Map in Java
Map<Object,String> mp=new HashMap<Object, String>();
mp.put(new Integer(2), "Two");
mp.put(new Integer(1), "One");
mp.put(new Integer(3), "Three");
mp.put(new Integer(4), "Four");
int sizeOfMap=mp.size();
System.out.println("Size of Map :"+sizeOfMap);
Output
Size of Map :4
Tags: Collections




Link to Us