本帖最后由 lcjasas 于 2013-4-4 06:24 编辑
import java.util.*;
class EntrySetDemo
{
public static void main(String[] arg)
{
Map<String,String> map = new HashMap<String,String>();
map.put("01","zs01");
map.put("02","zs02");
map.put("03","zs03");
map.put("04","zs04");
//将Map集合中的映射关系取出,存入到Set集合中
Set<Map.Entry<String,String>> entrySet = map.entrySet();
Iterator<Map.Entry<String,String>> it = entrySet.iterator();
while(it.hasNext())
{
Map.Entry<String,String> me = it.next();
System.out.println("entrySet:"+me);
}
}
}
取出的值是
Map.Entry<String,String> me = it.next();
System.out.println("entrySet:"+me);
与
Map.Entry<String,String> me = it.next();
String key = me.getKey();
String value = me.getValue();
System.out.println(key+":"+value);
感觉这样输出结果都是一样的,有本质上的区别吗?
|