HashMap的遍历
Map<String,String> mapList=new HashMap<String, String>();
mapList.put("AA", "測試");
mapList.put("BB", "我在");
//方式1 比較建議方式一的做法
Iterator iterator = mapList.keySet().iterator();
while(iterator.hasNext()) {
System.out.println(mapList.get(iterator.next()));
System.out.println(mapList.get(iterator.next()));
}
//方式2
// java.util.Iterator it = mapList.entrySet().iterator();
// while(it.hasNext()){
// java.util.Map.Entry entry = (java.util.Map.Entry)it.next();
entry.getKey() 返回與此項對應的鍵
entry.getValue() 返回與此項對應的值
// System.out.println(entry.getValue());
// System.out.println(entry.getKey());
// }
轉載于:https://www.cnblogs.com/shuenjian901/p/3577918.html
總結
以上是生活随笔為你收集整理的HashMap的遍历的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mac安装PhoneGap3
- 下一篇: mysql 断电 启动不了 start