A HashMap is class of collection framwork. It stores data in the form of name value pair. It provides number of methods. The size()
is also a method of HashMap class. It returns the size of HashMap, size means total number of keys in HashMap.
Code:
HashMapValues.java
|
package net.roseindia.java;import java.util.HashMap;public class HashMapSizeExample { public static void main(String[] arr) { /* Create a object of HfasHMap */HashMap<Integer, String> obMap = new HashMap<Integer, String>(); /* Add values into HashMap */obMap.put( new Integer(1), "AAAA");obMap.put( new Integer(2), "BBBB");obMap.put( new Integer(3), "CCCC");obMap.put( new Integer(4), "DDDD");obMap.put( new Integer(5), "EE"); /* Calculate the size of HashMap */System. out.println("Size of HashMap :" + obMap.size()); } } |
|
Size of HashMap :5 |