HashMap的遍历方式
前言
HashMap的遍历方式如下:
1. 迭代器遍历
2. forEach遍历
3. Lambda
4. Stream API
测试案例准备工作:
private HashMap<String, Integer> hashMap = new HashMap<String, Integer>();
@Before
public void init() {
hashMap.put("天踦爵", 18);
hashMap.put("鷇音子", 19);
hashMap.put("三余无梦生", 20);
hashMap.put("素还真", 21);
hashMap.put("解锋镝", 22);
}
一、Iterator遍历
1. 迭代器遍历EntrySet
@Test
public void test02() {
Iterator iterator = hashMap.entrySet