Java Collection Tutorial - Java Dictionary.put(K key, V value)








Syntax

Dictionary.put(K key, V value) has the following syntax.

public abstract V put(K key, V value)

Example

In the following code shows how to use Dictionary.put(K key, V value) method.

/*from   w w w .jav  a  2  s .com*/
import java.util.*;

public class Main {

   public static void main(String[] args) {
      
      Dictionary d = new Hashtable();

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

      // print how many times put was called
      System.out.println("Number of times put was called:" + d.size());
   }
}

The code above generates the following result.