首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Map 的两种遍历模式

2013-03-17 
Map 的两种遍历方式方法一HashMap map new HashMap()map.put(a, zhangsan)map.put(b, lisi)m

Map 的两种遍历方式
方法一HashMap map = new HashMap();map.put("a", "zhangsan");map.put("b", "lisi");map.put("c", "wangwu");System.out.println( map );Set set = map.entrySet();map.values();System.out.println( set );Iterator it = set.iterator();while ( it.hasNext() ) {Entry entry= (Entry) it.next();System.out.println( entry.getKey() +" "+entry.getValue());}//方法二//Set set = map.keySet();//Iterator it = set.iterator();//while( it.hasNext()){//String key = (String) it.next();//System.out.println( map.get(key));//}

?

热点排行