Dictionary remove() Method in Java Last Updated : 11 Oct, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The remove() method of Dictionary Class accepts a key as a parameter and removes the corresponding value mapped to the key. Syntax: public abstract V remove(Object key) Parameters: The function accepts a parameter key which denotes the key which is to be removed from the dictionary along with its mappings. Return Values: The function returns the value which was mapped to the key or returns NULL if the key had no mapping. Exception: The function throws no NullPointerException if the key passed as parameter is NULL. Below programs illustrate the use of java.util.Dictionary.remove() method: Program 1: Java // Java Program to illustrate // java.util.Dictionary.remove() method import java.util.*; class GFG { public static void main(String[] args) { // Create a new hashtable Dictionary<Integer, String> d = new Hashtable<Integer, String>(); // Insert elements in the hashtable d.put(1, "Geeks"); d.put(2, "for"); d.put(3, "Geeks"); // Print the Dictionary System.out.println("\nDictionary: " + d); // Display the removed value System.out.println(d.remove(3) + " has been removed"); // Print the Dictionary System.out.println("\nDictionary: " + d); } } Output: Dictionary: {3=Geeks, 2=for, 1=Geeks} Geeks has been removed Dictionary: {2=for, 1=Geeks} Program 2: Java // Java Program to illustrate // java.util.Dictionary.remove() method import java.util.*; class GFG { public static void main(String[] args) { // Create a new hashtable Dictionary<String, String> d = new Hashtable<String, String>(); // Insert elements in the hashtable d.put("a", "GFG"); d.put("b", "gfg"); // Print the Dictionary System.out.println("\nDictionary: " + d); // Display the removed value System.out.println(d.remove("a") + " has been removed"); System.out.println(d.remove("b") + " has been removed"); // Print the Dictionary System.out.println("\nDictionary: " + d); // returns true if (d.isEmpty()) { System.out.println("Dictionary " + "is empty"); } else System.out.println("Dictionary " + "is not empty"); } } Output: Dictionary: {b=gfg, a=GFG} GFG has been removed gfg has been removed Dictionary: {} Dictionary is empty Reference:https://docs.oracle.com/javase/7/docs/api/java/util/Dictionary.html#remove() Comment More infoAdvertise with us Next Article Dictionary remove() Method in Java R RICHIK BHATTACHARJEE Follow Improve Article Tags : Java Practice Tags : Java Similar Reads Dictionary isEmpty() Method in Java The isEmpty() method of Dictionary Class checks whether this dictionary has any key-value mappings or not. The function returns TRUE only if there is no entry in this dictionary. Syntax: public abstract boolean isEmpty() Return Value: The function returns TRUE if the dictionary is empty and FALSE ot 2 min read 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 TreeSet first() Method in Java The Java.util.TreeSet.first() method is used to return the first of the element of a TreeSet. The first element here is being referred to the lowest of the elements in the set. If the elements are of integer types then the smallest integer is returned. If the elements are of the string types then th 3 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 put() Method in Java with Examples 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. ke 2 min read Like