Dictionary remove() Method in Java
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 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); } } |
Dictionary: {3=Geeks, 2=for, 1=Geeks}
Geeks has been removed
Dictionary: {2=for, 1=Geeks}
Program 2:
// 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"); } } |
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()
Recommended Posts:
- Dictionary get() Method in Java with Examples
- Dictionary put() Method in Java with Examples
- Dictionary isEmpty() Method in Java
- Dictionary elements() Method in Java with Examples
- Dictionary keys() Method in Java with Examples
- Dictionary size() Method in Java with Examples
- LinkedTransferQueue remove() method in Java
- DelayQueue remove() method in Java
- PriorityBlockingQueue remove() method in Java
- LinkedList remove() Method in Java
- CopyOnWriteArraySet remove() method in Java
- ConcurrentHashMap remove() method in Java
- HashMap remove() Method in Java
- Map remove() Method in Java with Examples
- PriorityQueue remove() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



