我在Map 里存了一组数据,是在数据库查询出来的,里面有Null值,若m.get("v_contact_office"); 这样直接获取,如果遇到Null值就会报错了,我应该怎样判断是否有空值。

解决方案 »

  1.   

    汗一个...
    那就if一下呗...
    Object value = m.get("v_contact_office");
    if(value != null) {
     // DO SOMETHING
    }
      

  2.   

    可以在往Map中插入数据的时候把空值过滤掉,如果是空就不往Map里插入.如果想判断Map中是否有null的Key,null的Value可以通过下面两个方法来判断.
    HashMap map = new HashMap();
    map.put(null, null);
    map.put("name", "jack");
    System.out.println(map.get("name"));
    System.out.println(map.containsKey(null));
    System.out.println(map.containsValue(null));