public
boolean isEmpty()
Returns
true if this map contains no key-value mappings.
import java.util.*; class HashMapIsEmpty{ public static void main(String args[]){ HashMap<Integer, String> myMap; myMap = new HashMap<> (); System.out.print("Is myMap Empty "); System.out.println(myMap.isEmpty()); /* Add Data to myMap */ myMap.put(100, "Hi"); myMap.put(25, "How"); myMap.put(31, "Are"); System.out.print("Is myMap Empty "); System.out.println(myMap.isEmpty()); } }
Output
Is myMap Empty true Is myMap Empty false
No comments:
Post a Comment