話不多說,直奔主題,跟著小編一起往下看:
1.先將map對(duì)象轉(zhuǎn)成set,然后再轉(zhuǎn)為迭代器
1
2
3
4
5
6
|
Iterator iterator = map.entrySet().iterator(); while (iterator.hasNext()){ Entry entry = iterator.next(); System.out.println(entry.getKey()); // 獲取key System.out.println(entry.getValue()); // 獲取value } |
2.先將map轉(zhuǎn)為set類型的key值集合,然后轉(zhuǎn)為迭代器
1
2
3
4
5
6
|
Iterator iterator = map.keySet().iterator(); while (iterator.hasNext()){ Object key = (Object)iterator.next(); System.out.println(key); // 獲取key System.out.println(map.get(key)); // 獲取value } |
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,同時(shí)也希望多多支持服務(wù)器之家!
原文鏈接:http://www.cnblogs.com/houhaihu/p/6139181.html