Export (0) Print
Expand All

Hashtable.put Method

Visual Studio 2005

Adds an element at a specific key entry to a Hashtable object.

Package: java.util

Assembly: vjslib (in vjslib.dll)


public synchronized java.lang.Object put(
    java.lang.Object key,
    java.lang.Object element);

Parameters

key

The key entry at which the element is added.

element

The element to be added.

The element to be added to Hashtable.

In the following example, you create and initialize a Hashtable object and then you display the values stored in the object.

// HT-put1.jsl
// Hashtable.put example

import java.util.*;

public class MyClass
{
      public static void main(String[] args)
      {
            // Create a new hashtable object:
            Hashtable ht = new Hashtable();

            // Add some elements:
            System.out.println("The current value at \"4\" is " + ht.put("4", "Eve Kennedy"));
            // Add a key that is already present.
            System.out.println("The current value at \"4\" is " + ht.put("4", "Jack"));
      }
}

/*
Output:
The current value at “4” is null
The current value at “4” is Eve Kennedy 
*/

Community Additions

ADD
Show:
© 2014 Microsoft