示例:使用entrySet进行map的遍历,直接通过getKey()和getValue()获取键值
public static void main(String args[]) {
Map<String,String> map = new HashMap<String,String>(16);
map.put("1","张三");
map.put("2","李四");
map.put("3","王五");
Iterator<Map.Entry<String,String>> entryIterator = map.entrySet().iterator();
while (entryIterator.hasNext()) {
Map.Entry<String, String> entry = entryIterator.next();
System.out.println("key="+ entry.getKey() +"value="+ entry.getValue());
}
}
最后
以上就是饱满枕头最近收集整理的关于使用entrySet进行map的遍历的全部内容,更多相关使用entrySet进行map内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复