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






Hashtable: entrySet()

  
/*
{three=four, two=three, four=five, one=two}
4
three : four
two : three
four : five
one : two
three : four
two : three
four : five
one : two
 */

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MainClass {
  public static void main(String args[]) throws Exception {
    Hashtable hash = new Hashtable(89);
    hash.put("one", "two");
    hash.put("two", "three");
    hash.put("three", "four");
    hash.put("four", "five");
    System.out.println(hash);
    System.out.println(hash.size());
    Enumeration e = hash.keys();
    while (e.hasMoreElements()) {
      String key = (String) e.nextElement();
      System.out.println(key + " : " + hash.get(key));
    }
    Set set = hash.entrySet();
    Iterator it = set.iterator();
    while (it.hasNext()) {
      Map.Entry entry = (Map.Entry) it.next();
      System.out.println(entry.getKey() + " : " + entry.getValue());
    }
  }
}


           
         
    
  








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: get(E e)
9.Hashtable: isEmpty()
10.Hashtable: iterator()
11.Hashtable: keySet()
12.Hashtable: keys()
13.Hashtable: put(K key, V value)
14.Hashtable: putAll(Map t)
15.Hashtable: remove(Object key)
16.Hashtable: size()
17.Hashtable: values()