一、创建并添加元素
HashMap二、元素查找hashMap = new HashMap<>(); hashMap.put("a",99.5); hashMap.put("b",99.6); hashMap.put("c",99.7); hashMap.put("d",99.8); System.out.println(hashMap);
对于Map
map名.keyset():value集合
元素.getkey():元素的key 元素.getvalue():元素的value
public boolean checkLegality(String option) {
// TODO
return (options.keySet().contains(option));
}
三、遍历
1. 迭代器
Iterator> iterator=map.entrySet().iterator(); while(iterator.hasNext()){ Map.Entry entry=iterator1.next(); System.out.println(entry.getKey()); System.out.println(entry.getValue()); }
2. entry
for(Map.Entryentry : votePolled.entrySet()){ if(entry.getValue() == 0){ System.out.println("尚有投票人还未投票,不能开始计票"); return; }



