반복 맵

public static void main(String[] args) {
    Map map = new HashMap();
    map.put("1", "value1");
    map.put("2", "value2");
    map.put("3", "value3");
    //    :    ,    
    System.out.println("  Map.keySet  key value:");
    for (String key : map.keySet()) {
        System.out.println("key= " + key + " and value= " + map.get(key));
    }
    //    
    System.out.println("  Map.entrySet  iterator  key value:");
    Iterator> it = map.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry entry = it.next();
        System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
    }
    //    :  ,       
    System.out.println("  Map.entrySet  key value");
    for (Map.Entry entry : map.entrySet()) {
        System.out.println("key= " + entry.getKey() + " and value= "  + entry.getValue());
    }
    //    
    System.out.println("  Map.values()     value,     key");
    for (String v : map.values()) {
        System.out.println("value= " + v);
    }
}

좋은 웹페이지 즐겨찾기