import java.util.*;
public class IteratorTest {
public static void main(String[] args) {
HashMap map = new HashMap<>();
map.put(1,"hello");
map.put(2,"you");
map.put(3,"world");
//1.keySet的迭代器
Iterator> iterator = map.entrySet().iterator();
while(iterator.hasNext()) {
Map.Entry next = iterator.next();
System.out.print(next.getValue()+ " ");
}
System.out.println("\n------------------------------------");
// 2 .直接使用map.keySet
for(Integer i :map.keySet()){
System.out.print(map.get(i)+" ");
}
System.out.println("\n------------------------------------");
// 3.使用map的entrySet
Set> entries = map.entrySet();
for(Map.Entry entry : entries){
System.out.print(entry.getValue() + " ");
}
System.out.println("\n------------------------------------");
//4. map的values遍历所有的value,(不能便利key):Collection values = map.values();
for(String string : map.values()){
System.out.print(string + " ");
}
}
}