-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIteratorMap.java
More file actions
31 lines (25 loc) · 776 Bytes
/
Copy pathIteratorMap.java
File metadata and controls
31 lines (25 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.cpucode.java.iterator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* 迭代器来遍历 HashMap
* @author : cpucode
* @date : 2021/5/8
* @time : 21:08
* @github : https://github.com/CPU-Code
* @csdn : https://blog.csdn.net/qq_44226094
*/
public class IteratorMap {
public static void main(String[] args) {
Map<Integer, String> map = new HashMap();
map.put(1, "Java");
map.put(2, "C++");
map.put(3, "python");
Iterator<Map.Entry<Integer, String>> iterator = map.entrySet().iterator();
while (iterator.hasNext()){
Map.Entry<Integer, String> next = iterator.next();
System.out.println(next.getKey() + " " + next.getValue());
}
}
}