Dictionary put() Method in Java with Examples Last Updated : 27 Dec, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The put() method of Dictionary is used to insert a mapping into the dictionary. This means a specific key along with the value can be mapped into a particular dictionary. Syntax: DICTIONARY.put(key, value) Parameters: The method takes two parameters, both are of the Object type of the Dictionary. key: This refers to the key element that needs to be inserted into the dictionary for mapping. value: This refers to the value that the above key would map into. Return Value: The method returns the value to which the key is mapped. NULL is returned if the key is not mapped into any value. Below programs are used to illustrate the working of java.util.Dictionary.put() Method: Program 1: Java // Java code to illustrate the put() method import java.util.*; public class Dictionary_Demo { public static void main(String[] args) { // Creating an empty Dictionary Dictionary<Integer, String> dict = new Hashtable<Integer, String>(); // Inserting values into the Dictionary dict.put(10, "Geeks"); dict.put(15, "4"); dict.put(20, "Geeks"); dict.put(25, "Welcomes"); dict.put(30, "You"); // Displaying the Dictionary System.out.println("Initial Dictionary is: " + dict); // Inserting existing key along with new value String returned_value = (String)dict.put(20, "All"); // Verifying the returned value System.out.println("Returned value is: " + returned_value); // Displaying the new table System.out.println("New Dictionary is: " + dict); } } Output: Initial Dictionary is: {10=Geeks, 20=Geeks, 30=You, 15=4, 25=Welcomes} Returned value is: Geeks New Dictionary is: {10=Geeks, 20=All, 30=You, 15=4, 25=Welcomes} Program 2: Java // Java code to illustrate the put() method import java.util.*; public class Dictionary_Demo { public static void main(String[] args) { // Creating an empty Dictionary Dictionary<Integer, String> dict = new Hashtable<Integer, String>(); // Inserting values into the Dictionary dict.put(10, "Geeks"); dict.put(15, "4"); dict.put(20, "Geeks"); dict.put(25, "Welcomes"); dict.put(30, "You"); // Displaying the Dictionary System.out.println("Initial Dictionary is: " + dict); // Inserting existing key along with new value String returned_value = (String)dict.put(50, "All"); // Verifying the returned value System.out.println("Returned value is: " + returned_value); // Displaying the new table System.out.println("New Dictionary is: " + dict); } } Output: Initial Dictionary is: {10=Geeks, 20=Geeks, 30=You, 15=4, 25=Welcomes} Returned value is: null New Dictionary is: {10=Geeks, 20=Geeks, 30=You, 50=All, 15=4, 25=Welcomes} Comment More infoAdvertise with us Next Article Dictionary put() Method in Java with Examples C chinmoy lenka Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-Dictionary +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads Dictionary size() Method in Java with Examples The size() Method of Dictionary class in Java is used to know the size of the dictionary or the number of distinct keys present in the dictionary. Syntax: DICTIONARY.size() Parameters: The method does not accept any parameters. Return Value: The method returns the number of keys present in the dicti 2 min read Dictionary get() Method in Java with Examples The get() method of Dictionary class is used to retrieve or fetch the value mapped by a particular key mentioned in the parameter. It returns NULL when the dictionary contains no such mapping for the key. Syntax: DICTIONARY.get(Object key_element) Parameters: The method takes one parameter key_eleme 2 min read Dictionary keys() Method in Java with Examples The keys() method of Dictionary class in Java is used to get the enumeration of the keys present in the dictionary. Syntax: Enumeration enu = DICTIONARY.keys() Parameters: The method does not take any parameters. Return value: The method returns an enumeration of the keys of the Dictionary. Below pr 2 min read Dictionary elements() Method in Java with Examples The keys() method of Dictionary class in Java is used to get the enumeration of the values present in the dictionary. Syntax: Enumeration enu = DICTIONARY.elements() Parameters: The method does not take any parameters. Return value: The method returns an enumeration of the values of the Dictionary. 2 min read Collections list() method in Java with Examples The list() method of java.util.Collections class is used to return an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration. This method provides interoperability between legacy APIs that return enumerations and new APIs that requi 2 min read Like