Collection Of Values From Java Hashtable
Chapter:
Collections
Last Updated:
14-05-2016 19:08:47 UTC
Program:
/* ............... START ............... */
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Hashtable;
import java.util.Collection;
public class JavaHashTableCollectionOfValues {
public static void main(String[] args) {
Hashtable hashTable = new Hashtable();
hashTable.put("1","One");
hashTable.put("2","Two");
hashTable.put("3","Three");
Collection collection = hashTable.values();
System.out.println("Values of Collection created from Hashtable are :");
Iterator iterator = collection.iterator();
while(iterator.hasNext())
System.out.println(iterator.next());
collection.remove("One");
//print values of original values of Hashtable
System.out.println("Hashtable values after removal from Collection are :");
Enumeration enumeration = hashTable.elements();
while(enumeration.hasMoreElements())
System.out.println(enumeration.nextElement());
}
}
/* ............... END ............... */
Output
Values of Collection created from Hashtable are :
Three
Two
One
Hashtable values after removal from Collection are :
Three
Two
Tags
Collection, Collection Of Values From Java Hashtable, Java