61阅读

map.entry-Map.Entry是什么?

发布时间:2017-09-16 所属栏目:entry

一 : Map.Entry是什么?

就是泛型。。。K代表key的类型,V代表value的类型。。。

关键是你怎么模仿的。。。

KV就是Key-value,键值对的意思,Java中的集合类--Map接口的实现类中使用的较多。

一般来说Key是String类型的对象,Value是Object类型的对象,通过

key就可获得对应的value对象。

二 : 利用Map.Entry和foreach对Hashmap进行输出

1、利用Map.Entry

import java.util.*;
public class hashmap {
public static void main(String args[])
{
HashMap<Integer,String> hashmap= new HashMap<Integer,String>();
hashmap.put(1, "一");
hashmap.put(2, "二");
hashmap.put(3, "三");
hashmap.put(4, "四");
Set<Map.Entry<Integer,String>> allset =hashmap.entrySet();
Iterator<Map.Entry<Integer,String>> a = allset.iterator();
while(a.hasNext())
{
Map.Entry<Integer,String> me = a.next();//进行key和value分离
System.out.println(me.getKey()+ "--->" + me.getKey());//输出关键字和内容
}
}
}

2、用foreach对Hashmap进行输出:

import java.util.*;
public class hashmap {
public static void main(String args[])
{
HashMap<Integer,String> hashmap= new HashMap<Integer,String>();
hashmap.put(1, "一");
hashmap.put(2, "二");
hashmap.put(3, "三");
hashmap.put(4, "四");
for(Map.Entry<Integer,String> me:hashmap.entrySet())
{//me是存放hashmap中取出的内容,并用Map.Entry<Integer,String>指定其泛型
System.out.println(me.getKey()+ "-->" + me.getKey());
}
}
}

三 : entry的解释

entry的解释

entry和entrance和enter的区别?

entry的解释的参考答案

entry 是名词,表示进入.比如说我进入了,用名词表示就用entry

entrance是入口的意思

enter是及物动词,等于come into

本文标题:map.entry-Map.Entry是什么?
本文地址: http://www.61k.com/1082668.html

61阅读| 精彩专题| 最新文章| 热门文章| 苏ICP备13036349号-1