文章目录
Map
Map中的常用工具类
Map的第一种遍历
代码示范:
String s = null;
HashMap map = new HashMap<>();
Set<Character> set = map.keySet();
for (Character c : set) {
System.out.println(c + "----->" + map.get(c));
}
Map的第二种遍历
代码示范:
Map<Integer, Student> map = new HashMap<>();
map.put(1, new Student("小一", 11));
map.put(2, new Student("小二", 11));
Set<Map.Entry<Integer, Student>> set = map.entrySet();
Set<Integer> set1 = map.keySet();
for (Integer s : set1) {
System.out.println(s + " " + map.get(s));
}