博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Java] 遍历HashMap和HashMap转换成List的两种方式
阅读量:4578 次
发布时间:2019-06-09

本文共 1113 字,大约阅读时间需要 3 分钟。

遍历HashMap和HashMap转换成List

 

/*** convert the map to the list(1)*/public static void main(String[] args) {   Map
maps = new HashMap
(); maps.put("a", "aa"); maps.put("b", "bb"); maps.put("c", "cc"); maps.put("d", "dd"); maps.put("e", "ee"); maps.put("f", "ff"); List
strList = new ArrayList
(); for (String str : maps.values()) { strList.add(str); } for (int i = 0; i < strList.size(); i++) { System.out.println(strList.get(i)); }}

 

/*** convert the map to the list(2)*/public static void main(String[] args) {   Map
maps = new HashMap
(); maps.put("a", "aa"); maps.put("b", "bb"); maps.put("c", "cc"); maps.put("d", "dd"); maps.put("e", "ee"); maps.put("f", "ff"); List
strList = new ArrayList
(maps.values()); for (int i = 0; i < strList.size(); i++) { System.out.println(strList.get(i)); }}

 

控制台输出结果:

dd

aa
cc
ff
bb
ee

(HashMap无序排列)

转载于:https://www.cnblogs.com/jqmtony/p/3711508.html

你可能感兴趣的文章
公共POI导出Excel方法–java
查看>>
次短路——Dijkstra
查看>>
Enter Query Mode Search Tricks Using Enter_Query Built-in in Oracle Forms
查看>>
Form属性、内置子程序、触发器、系统变量
查看>>
广州夜景一
查看>>
JVM(2)--一文读懂垃圾回收
查看>>
游戏开发——战斗系统设计技巧
查看>>
Android ROM 制作教程
查看>>
Android模拟器使用SD卡
查看>>
STL学习笔记(关联式容器)
查看>>
FMDataBase 打开sqlite的外键约束功能
查看>>
二分图
查看>>
UVA10559&POJ1390 Blocks 区间DP
查看>>
[bzoj 3289] Mato的文件管理
查看>>
Flutter学习笔记(五)
查看>>
vSphere的exsi root密码忘记了
查看>>
svn的安装过程
查看>>
NSCopying简析
查看>>
oracle 用户 角色 权限
查看>>
MySQL 分区知识点(三)
查看>>