通过entuySet()结合迭代器遍历HashMap映射表
import java.util.HashMap;
public class HashMapTest {
public static void main(String[] args) {
HashMap<String, Integer> dict = new HashMap<String, Integer>(); // {}
dict.put("王崇", 1);
dict.put("西安科技大学", 2);
dict.put("软件工程", 1);
for (HashMap.Entry<String, Integer> entry : dict.entrySet()) {
System.out.println(entry.getKey() + " is in class " + entry.getValue());
}
}
}