Maps the specified key to the specified value in this hashtable. Neither the key nor the value can be null.
The value can be retrieved by calling the get method with a key that is equal to the original key.
Program
package com.candidjava;
import java.util.Hashtable;
import java.util.Properties;
/*
* @author : Mohan
* @description : The put(K key, V value) method is used to map the specified key to the specified value in this hashtable.
*/
public class PropertiesPut {
public static void main(String[] args) {
Properties properties = new Properties();
Hashtable ht = new Hashtable(properties);
ht.put("1", "hari");
ht.put("2", "anand");
ht.put("3", "vinoth");
ht.put("4", "mohan");
ht.put("5", "karthick");
System.out.println(ht);
ht.put("4", "SAKTHI");
System.out.println(ht);
}
}
Output
{5=karthick, 4=mohan, 3=vinoth, 2=anand, 1=hari}
{5=karthick, 4=SAKTHI, 3=vinoth, 2=anand, 1=hari}
Explanation
public V put(K key,V value)
Maps the specified key to the specified value in this hashtable. Neither the key nor the value can be null.
The value can be retrieved by calling the get method with a key that is equal to the original key.
Specified by:
put in interface Map
Specified by:
put in class Dictionary
Parameters:
key - the hashtable key
value - the value
Returns:
the previous value of the specified key in this hashtable, or null if it did not have one
Throws:
NullPointerException - if the key or value is null