Hashtable: keys() : Hashtable « java.util « Java by API






Hashtable: keys()

  
/*
 * Output: 
key = apple; value = red
key = strawberry; value = red
 */

import java.util.Enumeration;
import java.util.Hashtable;

public class MainClass {

  public static void main(String args[]) {
    Hashtable hashtable = new Hashtable();
    hashtable.put("apple", "red");
    hashtable.put("strawberry", "red");

    Enumeration e = hashtable.keys();
    while(e.hasMoreElements()) {
      Object k = e.nextElement();
      Object v = hashtable.get(k);
      System.out.println("key = " + k + "; value = " + v);
    } 

  }
}
    
           
         
    
  








Related examples in the same category

1.new Hashtable()
2.new Hashtable < K, V > ()
3.Hashtable: clear()
4.Hashtable: clone()
5.Hashtable: contains(Object value)
6.Hashtable: containsKey(Object key)
7.Hashtable: elements()
8.Hashtable: entrySet()
9.Hashtable: get(E e)
10.Hashtable: isEmpty()
11.Hashtable: iterator()
12.Hashtable: keySet()
13.Hashtable: put(K key, V value)
14.Hashtable: putAll(Map t)
15.Hashtable: remove(Object key)
16.Hashtable: size()
17.Hashtable: values()