例如:
1 Map map = new HashMap<String ,String>(); 2 System.out.println("判断map是否有内容:"+map.isEmpty());//返回true 3 System.out.println("判断map是否为null:"+map==null);//返回false
1 Map map = new HashMap<String ,String>(); 2 map=null; 3 System.out.println("判断map是否为null:"+(map==null));//结果为true 4 System.out.println("判断map是否有内容:"+map.isEmpty());//NullPointerException
1 Map map = new HashMap<String ,String>(); 2 map.put(null,null); 3 System.out.println("判断map是否为null:"+(map==null));//false 4 System.out.println("判断map是否有内容:"+map.isEmpty());//false
原文:http://www.cnblogs.com/zhima-hu/p/7615921.html