[Java] 遍历HashMap和HashMap转换成List的两种方式
2014-05-06 14:48
399 查看
遍历HashMap和HashMap转换成List
控制台输出结果:
dd
aa
cc
ff
bb
ee
(HashMap无序排列)
/** * convert the map to the list(1) */ public static void main(String[] args) { Map<String, String> maps = new HashMap<String, String>(); 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<String> strList = new ArrayList<String>(); 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<String, String> maps = new HashMap<String, String>(); 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<String> strList = new ArrayList<String>(maps.values()); for (int i = 0; i < strList.size(); i++) { System.out.println(strList.get(i)); } }
控制台输出结果:
dd
aa
cc
ff
bb
ee
(HashMap无序排列)
相关文章推荐
- Java中HashMap遍历的两种方式
- Java中HashMap遍历的两种方式
- Java中HashMap遍历的两种方式
- [转]Java中HashMap遍历的两种方式
- Java中HashMap遍历的两种方式
- Java中HashMap遍历的两种方式
- 转]Java中HashMap遍历的两种方式
- Java中HashMap遍历的两种方式
- Java中HashMap遍历的两种方式
- Java中HashMap遍历的两种方式
- Java中HashMap遍历的两种方式
- Java中HashMap遍历的两种方式
- Java中HashMap遍历的两种方式
- [Java][转] Java中HashMap遍历的两种方式
- Java中HashMap遍历的两种方式
- Java中HashMap遍历的两种方式
- Java中HashMap遍历的两种方式
- Java中HashMap遍历的两种方式
- Java中HashMap遍历的两种方式
- java中HashMap遍历的两种方式