黑马程序员技术交流社区

标题: 将双列集合键值对 变为单列集合键值对对象 的方法遍历 [打印本页]

作者: 于立员    时间: 2015-10-12 23:14
标题: 将双列集合键值对 变为单列集合键值对对象 的方法遍历
package com.heima;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class test6 {

        public static void main(String[] args) {
                HashMap<String, Integer> map = new HashMap<>();
                map.put("习~~",60);
                map.put("李~~",59);
                map.put("胡~~",66);
                map.put("温~~",70);
                map.put("周~~",73);
               
                Set<Map.Entry<String,Integer>> EntrySet = map.entrySet();
                Iterator<Map.Entry<String,Integer>> it = EntrySet.iterator();
                while (it.hasNext()) {
                        Map.Entry<String,Integer> en = it.next();
                        String key = en.getKey();
                        Integer value = en.getValue();
                        System.out.println(key + "=" + value);
                }
        }
}





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2