public static void main(String[] args) { Map<String, String> map = new HashMap<String, String>(); System.out.println("map為空:" + map.isEmpty()); //加入元素 map.put("1", "1"); System.out.println("map為空:" + map.isEmpty()); } 這里是用isEmpty()方法來做判斷,其實和map.size()也沒差,可以看下isEmpty()方法的源碼: public boolean isEmpty() { return size == 0; } 1 2 3 其實就是把map的size和0做個判斷,返回false和true結果。 map為空的問題 Map<String, Object> resultMap = new HashMap<>(); resultMap!=null