Java.util.Dictionary.isEmpty() Method


Advertisements


Description

The java.util.Dictionary.isEmpty() method check if this dictionary has no keys to value.

Declaration

Following is the declaration for java.util.Dictionary.isEmpty() method

public abstract boolean isEmpty()

Parameters

NA

Return Value

This method returns true if this dictionary has no keys to values; false otherwise.

Exception

NA

Example

The following example shows the usage of java.util.Dictionary.isEmpty() method.

Live Demo
package com.tutorialspoint;

import java.util.*;

public class DictionaryDemo {
   public static void main(String[] args) {

      // create a new hashtable
      Dictionary d = new Hashtable();

      // add elements in the hashtable
      d.put("1", "Chocolate");
      d.put("2", "Cocoa");
      d.put("5", "Coffee");

      // return true if this dictionary maps no keys to value.
      boolean b = d.isEmpty();
      System.out.println("Dictionary is empty:" + b);
   }
}

Let us compile and run the above program, this will produce the following result −

Dictionary is empty:false

java_util_dictionary.htm

Advertisements