心跳循环,map删除数据

  • Post author:
  • Post category:其他


 public static void main(String[] args) {
        Map<String, Map<String, Object>> map = new HashMap<>();
        Map<String, Object> map1 = new HashMap<>();
        map1.put("192.168.0.1", "08:01");
        Map<String, Object> map2 = new HashMap<>();
        map2.put("192.168.0.2", "08:02");
        Map<String, Object> map3 = new HashMap<>();
        map3.put("192.168.0.3", "08:03");
        map.put("admin", map1);
        map.put("caorixin", map2);
        map.put("lican", map3);
        System.out.println(map);
        for (Iterator<String> iterator = map.keySet().iterator(); iterator.hasNext();  ) {
            String key = iterator.next();
            Map<String,Object> Valuemap = map.get(key);
            for (Iterator<String> iterator1 = Valuemap.keySet().iterator(); iterator1.hasNext();){
                String key1 = iterator1.next();
                String val = (String) Valuemap.get(key1);
                if(val.equals("08:02")){
                    iterator.remove();
                }
            }
        }
        System.out.println(map);
    }



版权声明:本文为weixin_60457220原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。