首页 > 编程语言 > 详细

Java—Map.Entry

时间:2015-01-06 19:47:16      阅读:345      评论:0      收藏:0      [点我收藏+]

 

Map是java中的接口,Map.Entry是Map的一个内部接口。

Map提供了一些常用方法,如keySet()、entrySet()等方法。

keySet()方法返回值是Map中key值的集合;entrySet()的返回值也是返回一个Set集合,此集合的类型为Map.Entry。

Map.Entry是Map声明的一个内部接口,此接口为泛型,定义为Entry<K,V>。它表示Map中的一个实体(一个key-value对)。接口中有getKey(),getValue方法。

 

 

import java.util.HashMap;

import java.util.Iterator;

import java.util.Map.Entry; 

import java.util.Map; 

 

public class hello {

public static void main(String[] args){

hashMapTest();

 

}

 

public static void hashMapTest() {

System.out.println("----------------hashMapTest---------------");

 

Map<String,String> map1 = new HashMap<String,String>(); 

map1.put("1", "A");

map1.put("2", "B");

map1.put("3", "C");

map1.put("4", "D");

map1.put("5", "E");

map1.put("6", "F");

 

Iterator<Entry<String, String>> it = map1.entrySet().iterator();

while(it.hasNext()){

Map.Entry<String,String> e = (Map.Entry<String,String>) it.next();

System.out.println(e.getKey() + " : " + e.getValue()); 

}

 

System.out.println(map1);

}

}

 

Java—Map.Entry

原文:http://www.cnblogs.com/yuyue2014/p/4206597.html

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