当我们需要遍历HashMap时,可以使用以下几种方式:
- 使用迭代器(Iterator)遍历:
HashMap<String, Integer> hashMap = new HashMap<>();
// 添加键值对
hashMap.put("A", 1);
hashMap.put("B", 2);
hashMap.put("C", 3);
Iterator<Map.Entry<String, Integer>> iterator = hashMap.<
当我们需要遍历HashMap时,可以使用以下几种方式:
HashMap<String, Integer> hashMap = new HashMap<>();
// 添加键值对
hashMap.put("A", 1);
hashMap.put("B", 2);
hashMap.put("C", 3);
Iterator<Map.Entry<String, Integer>> iterator = hashMap.<