Java Collection Tutorial - Java Dictionary() Constructor


Dictionary() constructor from Dictionary has the following syntax.

public Dictionary()


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");
      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.