遍歷map方法推薦

Map<String, Object> map = new HashMap();
        map.put("1", "1");
        map.put("2", "2");
        map.put("3", "null");
        map.put("4", null);
        map.put("5", "5");
        map.put("6", "");
        map.put("7", "7");
        System.out.println("替換前map===="+map);

        for (Map.Entry<String, Object> entry : map.entrySet()) {
               System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
               //String xx = entry.getValue()+"";
               if("null".equals(entry.getValue())){
                   System.out.println(entry.getValue());
                   System.out.println((entry.getValue()+"").length());
                   entry.setValue(null);
               }
              }
        
        System.out.println("map===="+map);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章