To remove Key from Hastable
Previous | Home | Next |
This program shows how to use the Remove method of Hashtable class to remove the element from the table.
Remove () method is used to remove particular value from the table.
to remove all the values use
// clear() method of hashtable is used to remove all the keys from the table.
//tb.clear();
Remove () method is used to remove particular value from the table.
to remove all the values use
// clear() method of hashtable is used to remove all the keys from the table.
//tb.clear();
Enumeration e = tb.elements(); //it will print the remaining values of the table
Remove () method is used to remove particular value from the table.
to remove all the values use
// clear() method of hashtable is used to remove all the keys from the table.
//tb.clear();
Enumeration e = tb.elements(); //it will print the remaining values of the table
package Example;
import java .util.Enumeration;
import java .util.Hashtable;
public class RemoveHashtable {
/**
* @param args
*/
public static void main(String[] args) {
Hashtable tb = new Hashtable();
tb.put("4", "four");
tb.put("6", "six");
tb.put("3", "three");
tb.put("2", "two");
tb.put("5", "five");
System.out.println("The values of Hashtable are:"+ tb);
System.out.println("The size of hash table before removing all the keys is :" +tb.size());
//remove method is used to remove particular value from the table
Object obj= tb.remove("3");
System.out.println( obj + "The remove value from the table." );
Enumeration e = tb.elements(); //it will print the remaining values of the table
while (e.hasMoreElements())
System.out.println(e.nextElement());
// clear() method of hashtable is used to remove all the keys from the table.
//tb.clear();
System.out.println(" The size of Hash table after removingl the keys from the table is:"+ tb.size());
// TODO Auto-generated method stub
}
}
The values of Hashtable are:{6=six, 5=five, 4=four, 3=three, 2=two}
The size of hash table before removing all the keys is :5
threeThe remove value from the table.
six
five
four
two
The size of Hash table after removingl the keys from the table is:4
Previous | Home | Next |