Java Map 的三种遍历方式
来源:互联网 发布:linux下weblogic安装 编辑:程序博客网 时间:2024/05/16 12:15
第一种是遍历 map中键所对应的值
public static void work(Map<String, Student> map) {
Collection<Student> c = map.values();
Iterator it = c.iterator();
for (; it.hasNext();) {
System.out.println(it.next());
}
}
第二种是遍历 map中的 键 和 值
public static void workByKeySet(Map<String, Student> map) {
Set<String> key = map.keySet();
for (Iterator it = key.iterator(); it.hasNext();) {
String s = (String) it.next();
System.out.println(map.get(s));
}
}
第三种和第二种差不多,但是比较灵活
public static void workByEntry(Map<String, Student> map) {
Set<Map.Entry<String, Student>> set = map.entrySet();
for (Iterator<Map.Entry<String, Student>> it = set.iterator(); it.hasNext();) {
Map.Entry<String, Student> entry = (Map.Entry<String, Student>) it.next();
System.out.println(entry.getKey() + "--->" + entry.getValue());
}
}
}
- Java Map 的三种遍历方式
- JAVA Map 的三种遍历方式
- JAVA Map 的三种遍历方式
- JAVA Map的三种遍历方式
- Java 遍历map 的三种方式
- 遍历Map的三种方式:
- 遍历Map的三种方式
- 遍历Map的三种方式
- 遍历Map的三种方式
- Map集合的三种遍历方式
- map集合,遍历的三种方式
- [javase]遍历Map的三种方式
- Map集合遍历的三种方式
- 遍历map的三种方式
- Map的三种遍历方式
- Map集合遍历的三种方式
- map的三种遍历方式
- map的三种遍历方式
- 60个开发者不容错过的免费资源库
- C语言数据结构----栈的应用(四则运算)
- 转载_内核启动详解
- Eclipse 配置Tomcat启动参数 Java EE IDE for Web Developers. Version: Helios Service Release 2
- pf-ring
- Java Map 的三种遍历方式
- 用Rebar来创建和发布一个Erlang的项目
- intellij idea 编译信息乱的解决方法
- sql语句中条件查询like的效率,及使用规范.
- C# 连接SQL数据库 常用连接字符串
- 创业文摘
- Qt自定义事件的实现
- YUV格式
- log4j分模块文件存储