remove(Object, Object): This method is available in java.util.Hashtable class of Java.
Syntax:
boolean java.util.Hashtable.remove(Object key, Object value)
This method takes two arguments. This method removes the entry for the specified key only if it is currently mapped to the specified value.
Parameters: Two parameters are required for this method.
key: key with which the specified value is associated.
value: value expected to be associated with the specified key.
Returns: true if the value was removed.
Exceptions: NA
Approach
Java
import java.util.Hashtable;public class Hashtableremove2 {public static void main(String[] args) {Hashtable<String, Integer> hashtable =new Hashtable<String, Integer>();hashtable.put("Hello", 1);hashtable.put("World", 2);Object key = "Hello";Object value = 1;hashtable.remove(key, value);System.out.println(hashtable);}}
Output:
{World=2}
No comments:
Post a Comment