Hashtable clear Example
Hashtable class clear method example. This example shows you how to use clear method.
Hashtable class clear method example.clear method Clears the hashtable so that it contains no keys.
syntax - void clear()
Her is the code
/**
* @ # Clear.java
* A class repersenting use to clear method
* of HashMap class in java.util package
* version 19 May 2008
* author Rose India
*/
import java.util.*;
public class Clear {
public static void main(String args[]) {
Hashtable table = new Hashtable();
//Put value into the table
table.put(1, "A");
table.put(2, "B");
table.put(3, "C");
table.put(4, "D");
System.out.println("table :" + table);
//clear all maps
table.clear();
System.out.println("table :" + table);
}
} |
Output
table : {4=D, 3=C, 2=B, 1=A}
table : {} |
|