首页 > 其他 > 详细

Map集合的遍历.

时间:2019-04-01 19:56:33      阅读:114      评论:0      收藏:0      [点我收藏+]
 1 package collction.map;
 2 
 3 import java.util.HashMap;
 4 import java.util.Iterator;
 5 import java.util.Map;
 6 import java.util.Set;
 7 
 8 public class Demo_1 {
 9     public static void main(String[] args) {
10         mapIterator();
11     }
12   public static void mapIterator(){
13       Map<Integer, String> map = new HashMap<>();
14       map.put(1, "abc");
15       map.put(2, "cdf");
16 //      使用map中的keset()方法 返回一个含有键的set集合
17      Set<Integer> set =map.keySet();
18 //     遍历Set中的集合,获取Set集合中的所有的元素
19      Iterator<Integer> it =set.iterator();
20      while(it.hasNext()){
21         Integer key = it.next();
22 //        调用Map集合中的方法get()通过键获取值。
23         String value =map.get(key);
24         System.out.println(key+"..."+value);
25         
26          
27      }
28   }
29 }

 

Map集合的遍历.

原文:https://www.cnblogs.com/hnwxp/p/10638172.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!