• Java学习——HashMap


    遍历

    Map map = new HashMap(); 
    Iterator iter = map.entrySet().iterator(); 
    while (iter.hasNext()) { 
        Map.Entry entry = (Map.Entry) iter.next(); 
        Object key = entry.getKey(); 
        Object val = entry.getValue(); 

    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;
    
    public class testMap {
        public static void main(String[] args){
            testMap test = new testMap();
            HashMap map = new HashMap<String, String>();
            map.put("a", "123");
            map.put("a", "456");
            map.put("b", "789");
            test.transMap(map);
        }
        void transMap(HashMap map){
            Iterator iter = map.entrySet().iterator();
            while(iter.hasNext()){
                Map.Entry entry =(Map.Entry)iter.next();
                Object key = entry.getKey();
                Object val = entry.getValue();
                System.out.println((String)key + ":" + (String)val);
            }
        }
    }

    输出

    a:456
    b:789

    dd

  • 相关阅读:
    sh脚本学习笔记
    idea常见快捷键
    linux操作命令笔记
    【题解】[国家集训队]圈地计划
    【题解】[国家集训队]happiness
    【题解】小M的作物
    cpu的MMU
    socat命令
    strace命令
    Linux的文件描述符
  • 原文地址:https://www.cnblogs.com/kaituorensheng/p/5840842.html
Copyright © 2020-2023  润新知