Java Collection Tutorial - Java Dictionary() Constructor








Syntax

Dictionary() constructor from Dictionary has the following syntax.

public Dictionary()

Example

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

//ww w .  j ava  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.