一.概述
HashMap是以Hash表来存储Key的集合,Key可为null,value可为多个null
二.例子
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("1", "huhue");
hashMap.put("3","haha");
hashMap.put("4", "lala");
hashMap.remove("1");
final Collection<String> values = hashMap.values();
hashMap.replace("3", "dada");
hashMap.containsKey("1");
hashMap.containsValue("huhue");
Set<Map.Entry<String, String>> entrySet = hashMap.entrySet();
for (Map.Entry entry : entrySet) {
entry.getKey();
entry.getValue();
}
Set<String> set = hashMap.keySet();
for (String s : set) {
hashMap.get(s);
}
本文深入解析了HashMap的数据结构原理,展示了如何使用HashMap进行增删改查操作,包括put、remove、replace、containsKey和containsValue等方法的使用,并介绍了如何遍历HashMap。
1537

被折叠的 条评论
为什么被折叠?



