3:30 am - Saturday August 19, 2017

Hash table example program to clear the hash table value using clear() method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This Program is used clear the hash table values using Clear() method.

Example Program


import java.util.Hashtable;

import java.util.Iterator;

public class SimpleHashTable {

public static void main(String[] args) {

Hashtable hm = new Hashtable();

hm.put(100, "Veermain");

hm.put(101, "Mdhan");

hm.put(102, "Sakthi");

hm.put(103, "Vivek");

System.out.println("Before hashtable");

System.out.println("Hashtable content" + hm);

System.out.println("After hashtable");

hm.clear();

System.out.println("Hashtable content" + hm);

hm.clear();

System.out.println(hm);

}

}

 

Output

Before hashtable

Hashtable content{103=Vivek, 102=Sakthi, 101=Mdhan, 100=Veermain}

After hashtable

Hashtable content{}

 

Explanation

 

public void clear()

 

Clears this hashtable so that it contains no keys.

 

Specified by

clear in interface Map<K,V>

BACK

Filed in: Z-A All Java Codes

Comments are closed.