package MapTest;
import java.util.*;
public class HashMapTest {
public static void main(String[] args) {
HashMap<String,Integer> hashMap = new HashMap();
hashMap.put("张三",12);
hashMap.put("李四",13);
hashMap.put("王五",14);
Set<Map.Entry<String, Integer>> entrySet = hashMap.entrySet();
Iterator<Map.Entry<String, Integer>> entryIterator = entrySet.iterator();
while (entryIterator.hasNext()) {
Object next = entryIterator.next();
System.out.println(next);
}
for (Map.Entry<String, Integer> stringIntegerEntry : entrySet) {
System.out.println(stringIntegerEntry);
Java笔记总结(四十九)---HashMap通过entrySet遍历(增强for和迭代器)
于 2022-05-04 10:32:51 首次发布