public
int size()
Returns
the number of key-value mappings in this map.
import java.util.*; class HashMapSize{ public static void main(String args[]){ HashMap<Integer, String> myMap; myMap = new HashMap<> (); System.out.print("Size Of myMap is "); System.out.println(myMap.size()); /* Add Data to myMap */ myMap.put(100, "Hi"); myMap.put(25, "How"); myMap.put(31, "Are"); System.out.print("Size Of myMap is "); System.out.println(myMap.size()); } }
Output
Size Of myMap is 0 Size Of myMap is 3
No comments:
Post a Comment