clear(): This method is available in java.util.Hashtable class of Java.
Syntax:
void java.util.Hashtable.clear()
This method clears this hashtable so that it contains no keys.
Parameters: NA
Returns: NA
Exceptions: NA
Approach
Java
import java.util.Hashtable;public class Hashtableclear {public static void main(String[] args) {Hashtable<String, Integer> hashtable =new Hashtable<String, Integer>();hashtable.put("Hello", 1);hashtable.put("World", 2);System.out.println("Hashtable elementsbefore clear: " + hashtable);hashtable.clear();System.out.println("Hashtable elementsafter clear: " + hashtable);}}
Output:
Hashtable elements before clear: {World=2, Hello=1}
Hashtable elements after clear: {}
No comments:
Post a Comment