1.Basic java example program to remove all elements from hashtable
Output:
- Object remove(Object key) This method used to remove value pair from hashtable
- void clear() this method removes all elements from hashtable
- package com.removevalueHashtable;
- import java.util.Hashtable;
- import java.util.Enumeration;
- public class HashtableExample{
- public static void main(String[] args) {
- //create Hashtable object
- Hashtable<String,String> hashtable = new Hashtable<String,String>();
- //add key value pairs to Hashtable
- hashtable.put("1","Java Interview Questions");
- hashtable.put("2","Java Interview Programs");
- hashtable.put("3","Concept and example program");
- hashtable.put("4","Concept and interview Questions");
- hashtable.put("5","Java Quiz");
- hashtable.put("6","Real time examples");
- Object obj = ht.remove("2");
- System.out.println(obj + " Removed from Hashtable");
- Enumeration e=hashtable.elements();
- while (e.hasMoreElements()) {
- System.out.println(e.nextElement());
- }
- hashtable.clear();
- System.out.println("Total key value pairs in Hashtable are : " + hashtable.size());
- }
- }
Output:
- Java Interview Programs Removed from Hashtable
- Real time examples
- Java Quiz
- Concept and interview Questions
- Concept and exampe program
- Java Interview Questions
- Total key value pairs in Hashtable are : 0
Bagikan
Remove all elements from hashtable java example
4/
5
Oleh
Kris Kimcil