A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© xgm 中级黑马   /  2016-3-18 00:39  /  874 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. /**
  2. * HashMap的迭代
  3. * @author Administrator
  4. *
  5. */
  6. public class EntryTest {

  7.         public static void main(String[] args) {
  8.                
  9.                 Map<Integer,String> maps = new HashMap<Integer,String>();
  10.                
  11.                 maps.put(1, "aa");
  12.                 maps.put(2, "bb");
  13.                 maps.put(3, "cc");
  14.                 maps.put(4, "dd");
  15.                
  16.                
  17.                 Set<Map.Entry<Integer,String>> set = maps.entrySet();
  18.                
  19.                 for(Map.Entry<Integer, String> entry:set){
  20.                         System.out.println(entry.getKey()+"===="+entry.getValue());
  21.                 }
  22.                
  23.                 Set<Integer> set1= maps.keySet();
  24.                 for(Integer i:set1){
  25.                         System.out.println(maps.get(i));
  26.                 }
  27.         }
  28. }
复制代码

3 个回复

倒序浏览
这绝对是水贴
回复 使用道具 举报
Map迭代的第二种方式,遍历Map.Entry类,但是哪种更快呢,求大神解答
回复 使用道具 举报
不错....
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马