1.Basic java collection framework example program to get Value collection from hashtable
Output:
- Collection values() This method used to get collection of values
- Important note is that if any value is removed from set the original hashtable key also removed
- package com.setviewHashtable;
- import java.util.Hashtable;
- import java.util.Enumeration;
- import java.util.Iterator;
- import java.util.Set;
- public class HashtableExample{
- public static void main(String[] args) {
- //create Hashtable object
- Hashtable<String,String> hashtable = new Hashtable<String,String>();
- //add key value pairs to Hashtable
- hashtable.put("1","Java Interview Questions");
- hashtable.put("2","Java Interview Programs");
- hashtable.put("3","Concept and example program");
- hashtable.put("4","Concept and interview Questions");
- hashtable.put("5","Java Quiz");
- hashtable.put("6","Real time examples");
- Collection c = hashtable.values();
- System.out.println("Values of Collection created from Hashtable are :");
- //iterate through the Set of keys
- Iterator itr = c.iterator();
- while(itr.hasNext())
- System.out.println(itr.next());
- c.remove("Java Quiz");
- System.out.println("Elements in hash table");
- Enumeration e=hashtable.elements();
- while (e.hasMoreElements()) {
- System.out.println(e.nextElement());
- }
- }
- }
Output:
- Values of Collection created from Hashtable are :
- Real time examples
- Java Quiz
- Concept and interview Questions
- Concept and example program
- Java Interview Programs
- Java Interview Questions
- Elements in hash table
- Real time examples
- Concept and interview Questions
- Concept and example program
- Java Interview Programs
- Java Interview Questions