Map list的遍历问题
来源:互联网 发布:js触发事件 自动 编辑:程序博客网 时间:2024/06/05 19:04
1、在实际开发过程中Map 的实现类HashMap,使用极为频繁,HashMap有四种遍历方式
Map<String, String> map = new HashMap<String, String>();
// 第一种操作
for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println("key---" + entry.getKey() + "+++"
+ entry.getValue());
}
// 第二种操作
Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> itemap = it.next();
System.out.println(itemap.getKey() + "---" + itemap.getValue());
}
// 第三种操作
for (String s : map.keySet()) {
System.out.println(s + "----" + map.get(s));
}
// 第四种操作
for (String value : map.values()) {
System.out.println(value);
}
2、List主要实现类是ArrayList,遍历形式3中
1.增强for循环
for(String str : list) {//其内部实质上还是调用了迭代器遍历方式,这种循环方式还有其他限制,不建议使用。 System.out.println(str);}
2.普通for循环
for( int i = 0 ; i < list.size() ; i++) {//内部不锁定,效率最高,但在多线程要考虑并发操作的问题。 System.out.println(list.get(i));}
3.迭代器遍历
Iterator<String> iter = list.iterator();while(iter.hasNext()){ //执行过程中会执行数据锁定,性能稍差,若在循环过程中要去掉某个元素只能调用iter.remove()方法。 System.out.println(iter.next());}
- Map list的遍历问题
- List,Map的遍历
- 关于jstl中foreach遍历list中map的问题
- set,list,map的遍历
- List 和 Map 的遍历
- 遍历含有map的list
- jdk8的遍历list,list转map
- map、list、map(Object,map)的前台获取遍历
- List 、Set 、Map 的遍历方式
- 模板中 List 和 Map 的遍历
- 遍历list,map,treemap的方法
- 数组、List以及Map的遍历
- List,Map在遍历的时候remove
- freemaker中list与map的遍历
- List、Set、Map的遍历方法
- List 和Map的遍历方式
- Map、Set、List集合的遍历
- List,Map,Stack,Queue,Set的遍历
- 在Vue项目中使用easyScroll滚动条插件
- HTTPS握手过程与对称加密、非对称加密
- PullToRefreshBase添加头部视图
- shell脚本实例
- Linux下限制IP访问
- Map list的遍历问题
- tcp/ip-路由相关结构
- Android中轮播图的实现
- 二叉树的子树 解题报告
- Python 通过whl后缀安装scipy
- vertical-align属性
- 使用getopt命令解析shell脚本的命令行选项
- phaIcon问题
- FTP 服务器的上传和下载