本文介绍map类在无需key的情况下遍历value的两种方法,以此方便日后回顾
假设有实体类为Student,创建map为
Map<String,Student> StudentMap= new HashMap<>();
利用超级for循环遍历value
for(Map.Entry<String,Student> map: StudentMap.entrySet()) {
Student student = map.getValue();
}
利用迭代器遍历value
Iterator<Map.Entry<String,Student>> it = StudentMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, StudentMap> entry = it.next();
Student student = entry.getValue();
}