VOOZH about

URL: https://www.geeksforgeeks.org/java/hashtable-clear-method-in-java/

⇱ Hashtable clear() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Hashtable clear() Method in Java

Last Updated : 2 Jun, 2023

The java.util.Hashtable.clear() method in Java is used to clear and remove all of the keys from a specified Hashtable. 

Syntax:

Hash_table.clear()

Parameters: The method does not accept any parameters. 

Return Value: The method does not return any value. Below programs are used to illustrate the working of java.util.Hashtable.clear() Method: 

Program 1: 

Output:
The Hashtable is: {10=Geeks, 20=Geeks, 30=You, 15=4, 25=Welcomes}
Finally the table looks like this: {}

Program 2: 

Output:
The Hashtable is: {You=30, Welcomes=25, 4=15, Geeks=20}
Finally the table looks like this: {}

Note: The same operation can be performed with any type of variation and combination of different data types.

Comment