遍历map集合
来源:互联网 发布:网上刷火车票软件 编辑:程序博客网 时间:2024/06/07 00:42
public static void main(String[] args) { Map<String, String> map = new HashMap<String, String>(); map.put("1", "value1"); map.put("2", "value2"); map.put("3", "value3"); //第一种:普遍使用,二次取值 System.out.println("通过Map.keySet遍历key和value:"); for (String key : map.keySet()) { System.out.println("key= "+ key + " and value= " + map.get(key)); } //第二种 System.out.println("通过Map.entrySet使用iterator遍历key和value:"); Iterator<Map.Entry<String, String>> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> entry = it.next(); System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue()); } //第三种:推荐,尤其是容量大时 System.out.println("通过Map.entrySet遍历key和value"); for (Map.Entry<String, String> entry : map.entrySet()) { System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue()); } //第四种 System.out.println("通过Map.values()遍历所有的value,但不能遍历key"); for (String v : map.values()) { System.out.println("value= " + v); } }
0 0
- 【Map】Map集合的遍历:
- struts2遍历Map集合
- 遍历map集合
- map集合遍历方式
- Map集合的遍历
- map集合的遍历
- 遍历Map集合
- Map集合遍历
- java遍历Map集合
- 遍历Map集合方式
- Map集合视图遍历
- java 遍历map集合
- 遍历Map集合
- Map集合的遍历
- Map集合遍历
- 遍历map集合
- Map集合遍历
- Java遍历Map集合
- SPOJ JPIX Pixel Shuffle
- Android笔记----app应用更新
- keil如何仿真
- 分组背包hdu 3033 至少选一个
- java实现Excel压缩成Zip导出
- 遍历map集合
- python编码错误:UnicodeDecodeError: 'utf8' codec can't decode
- netty源码分析 之四 transport(ChannelPipeline)
- 常用网络模型结构LeNet,AlexNET,VGG,BN-inception,ResNet网络模型简介和资料整理--caffe学习(8)
- java web小结(一)
- JSONObject与JSONArray的使用
- 虚拟机中的Linux安装VMware Tools的方法
- json技术比较
- dubbo + zookeeper + spring 实战++