The java.util Hashtable class is a collection that stores key/value pairs, where each key and value is of type Object. It is similar to the HashMap class, but Hashtable is synchronized and is thread-safe. The isEmpty() method is used to check if the Hashtable contains no elements or not.
Example 1:
Hashtable numbers = new Hashtable(); System.out.println("Is the Hashtable empty? " + numbers.isEmpty());
Output: Is the Hashtable empty? true
In this example, we create a new Hashtable called "numbers" and then check if it is empty using the isEmpty() method. Since we haven't added any key/value pairs to the Hashtable yet, the output will be "true".
Example 2:
Hashtable cities = new Hashtable(); cities.put("New York", "USA"); cities.put("Paris", "France"); cities.put("Tokyo", "Japan"); System.out.println("Is the Hashtable empty? " + cities.isEmpty());
Output: Is the Hashtable empty? false
In this example, we create a new Hashtable called "cities" and then add three key/value pairs to it. After that, we check if the Hashtable is empty or not using the isEmpty() method. Since we have added three key/value pairs to the Hashtable, the output will be "false".
The java.util Hashtable class is part of the Java Collections Framework.
Java Hashtable.isEmpty - 30 examples found. These are the top rated real world Java examples of java.util.Hashtable.isEmpty extracted from open source projects. You can rate examples to help us improve the quality of examples.