码迷,mamicode.com
首页 > 其他好文 > 详细

entrySet

时间:2020-03-20 00:28:45      阅读:61      评论:0      收藏:0      [点我收藏+]

标签:腾讯   int   阿里   put   imp   hash   for   main   nbsp   

方法:

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

标签:腾讯   int   阿里   put   imp   hash   for   main   nbsp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!