Map: keySet() : Map « java.util « Java by API






Map: keySet()

 
/*
Key Adobe; Value Mountain View, CA
Key IBM; Value White Plains, NY
Key Learning Tree; Value Los Angeles, CA
*/       
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class MainClass {

  public static void main(String[] argv) {
    Map map = new HashMap();

    map.put("Adobe", "Mountain View, CA");
    map.put("IBM", "White Plains, NY");
    map.put("Learning Tree", "Los Angeles, CA");

    Iterator k = map.keySet().iterator();
    while (k.hasNext()) {
      String key = (String) k.next();
      System.out.println("Key " + key + "; Value " + (String) map.get(key));
    }
  }
}

           
         
  








Related examples in the same category

1.implements Map
2.java.util.Map.Entry
3.Map: clear()
4.Map: containsKey(Object key)
5.Map: containsValue(Object value)
6.Map: equals(Object o)
7.Map: get(Object key)
8.Map.Entry: getKey()
9.Map.Entry: getValue()
10.Map: put(T key, T value)
11.Map: putAll(Map m)
12.Map: remove(Object key)
13.Map: size()
14.Map: values()