import java.util.HashMap;
import java.util.Map;
public class IsEmpty {
public static void main(String[] args) {
Map map = new HashMap();
if (!map.isEmpty()) {
System.out.println("Size of an HashMap: "+map.size());
} else {
System.out.println("HashMap is Empty");
}
map.put("ONE", 1);
map.put("TWO", 2);
map.put("THREE", 3);
map.put("FOUR", 4);
map.put("FIVE", 5);
System.out.println("Inserted elements in the HashMap");
if (!map.isEmpty()) {
System.out.println("Size of an HashMap: "+map.size());
} else {
System.out.println("HashMap is Empty");
}
}
}
=========result============
HashMap is Empty
Inserted elements into the HashMap
Size of an HashMap: 5
from:http://examplesofjava.com/hashmap/hashmap-isempty-example.html Salute to the author
|