首页 > 其他 > 详细

entrySet

时间:2020-03-20 01:15:48      阅读:69      评论:0      收藏:0      [点我收藏+]

方法:

1.public K getKey() :获取Entry对象中的键。
2.public V getValue() :获取Entry对象中的值。
3.public Set<Map.Entry<K,V>> entrySet() : 获取到Map集合中所有的键值对对象的集合(Set集合)。

代码:

 1 import java.util.HashMap;
 2 import java.util.Map;
 3 import java.util.Set;
 4 
 5 public class EntryDemo {
 6     public static void main(String[] args) {
 7         //创建Map集和对象
 8         HashMap<String, String> hashMap = new HashMap<>();
 9         hashMap.put("马云","阿里巴巴");
10         hashMap.put("马化腾","腾讯");
11         hashMap.put("王健林","万达");
12         //获取所有的 Entry 对象
13         Set<Map.Entry<String, String>> entries = hashMap.entrySet();
14         //遍历得到每一个entry对象
15         for(Map.Entry<String,String> entry : entries){
16             System.out.println(entry.getKey()+" : "+entry.getValue());
17         }
18 
19 
20     }
21 }

 

entrySet

原文:https://www.cnblogs.com/0error0warning/p/12528461.html

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