HashMap
是一个将两个key=value
存储为对的对象。 该HashMap
允许不同步的空值和空键,并且不保证映射的顺序。
["key","value"] = ["java","mkyong.com"]
1. HashMap Basic
1.1添加项目
Map map = new HashMap<String, String>();
map.put("PostgreSQL", "Free Open Source Enterprise Database");
1.2取得物品
map.get("PostgreSQL"); // output : Free Open Source Enterprise Database
1.3更新项目
map.put("PostgreSQL", "Still the best!");
map.get("PostgreSQL"); // output : Still the best!
// @Since 1.8
map.replace("PostgreSQL", "Still the best! 2");
map.get("PostgreSQL"); // output : Still the best! 2
1.4移除物品
map.remove("PostgreSQL");
map.get("PostgreSQL"); // output : null
1.5删除所有内容
map.clear();
1.6取得尺寸
map.size();