Java Dictionary.size()

Syntax

Dictionary.size() has the following syntax.

public abstract int size()

Example

In the following code shows how to use Dictionary.size() method.


/* w  ww . j av  a 2s  . c o  m*/
import java.util.*;

public class Main {

   public static void main(String[] args) {

      // Create a new hasthtable
      Dictionary d = new Hashtable();

      // Put some elements
      d.put("1", "from java2s.com");
      d.put("2", "Cocoa");
      d.put("5", "Coffee");

      // print the size of the dictionary
      System.out.println("Size of dictionary:" + d.size());;
   }
}

The code above generates the following result.