清空整个map -- clear()

清空整个map – clear()

  HashMap hashMap = new HashMap();
    hashMap.put("1", "mqboss");
    hashMap.put("2", "Jboss");
    System.out.println("hashMap: " + hashMap);
    hashMap.clear();
    System.out.println("hashMap: " + hashMap);

测试输出:

  hashMap: {2=Jboss, 1=mqboss}
  hashMap: {}

你可能感兴趣的:(java)