map集合的遍历
来源:互联网 发布:林向正手抛网淘宝价格 编辑:程序博客网 时间:2024/05/20 03:44
直接上代码:
package linruozhuo;import java.util.HashMap;import java.util.Iterator;import java.util.Map;public class JavaJihe { public static void main(String[] args) { Map<String ,String > map1 = new HashMap<String ,String >(); map1.put("1", "小米"); map1.put("2", "小红"); map1.put("3", "小明"); map1.put("4", "小华"); //通过键找值遍历(效率低) System.out.println("通过Map.keySet遍历key和value:"); for (String key : map1.keySet()) { System.out.println("key= "+ key + " and value= " + map1.get(key)); } // Iterator遍历 System.out.println("通过Iterator遍历key和value:"); Iterator<Map.Entry<String,String >> entries = map1.entrySet().iterator(); while (entries.hasNext()) { Map.Entry<String,String > entry = entries.next(); System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue()); } //foreach分别遍历key和value System.out.println("foreach分别遍历key和value:"); for (String key : map1.keySet()) { System.out.println("key= "+ key); } for (String value : map1.values()) { System.out.println("value= "+ value); } //for循环 System.out.println("for遍历key和value:"); for (int i = 1; i <= map1.size(); i++) { String key = i+""; System.out.println("key= "+ (i) + " and value= " + map1.get(key)); } }}
阅读全文
0 0
- Map集合的遍历
- map集合的遍历
- Map集合的遍历
- Map集合的遍历
- Map集合的遍历
- map集合的遍历
- Map集合的遍历
- Map集合的遍历
- map集合的遍历
- Map集合的遍历
- map集合的遍历
- Map集合的遍历?
- 【Map】Map集合的遍历:
- 关于Map集合的遍历
- map集合遍历的方法
- Map集合的遍历方法
- 遍历Map集合的方法
- java集合map的遍历
- mysql 分区分表
- swagger注释API详细说明
- Makefile的结构和使用
- Object Detection系列(三) Fast R-CNN
- Java data
- map集合的遍历
- 2016APP界面视觉设计尺寸
- Linux初学者日志
- 获取运行时期的对象类型
- centos7 安装apache教程以及安装后无法访问的原因以及解决方案
- SpringBoot项目取消数据库配置
- 如何让eacharts 堆叠图不堆叠
- LUOGU P1843 奶牛晒衣服
- 论文笔记:Self-critical Sequence Training for Image Captioning