HashTable void clear() Method Example Program


Clears this hashtable so that it contains no keys.

Program

package com.candidjava;

import java.util.Hashtable;

/**
 * @author: Hari Haran
 * @discription: The clear() method is used to clear this hashtable so that it
 *               contains no keys.
 */

public class HashTableClear {
	public static void main(String args[]) {

		Hashtable<Integer, String> ht = new Hashtable<Integer, String>();

		ht.put(1, "Anand");
		ht.put(2, "Hari Haran");
		ht.put(3, "Kamal");
		ht.put(4, "Karthikeyan");
		ht.put(5, "Mohan");
		ht.put(6, "Vinoth");
		ht.put(7, "Hari Haran");

		System.out.println("Hash table content: " + ht);

		ht.clear();

		System.out.println("Hash table content after clear: " + ht);
	}
}

Output

Hash table content: {7=Hari Haran, 6=Vinoth, 5=Mohan, 4=Karthikeyan, 3=Kamal, 2=Hari Haran, 1=Anand}
Hash table content after clear: {}

Explanation

public void clear()
Clears this hashtable so that it contains no keys.
Specified by:
clear in interface Map<K,V>


Related Post

Comments


©candidjava.com