How does one convert a HashMap to a List in Java?

后端 未结 7 1163
春和景丽
春和景丽 2020-12-08 01:35

In Java, how does one get the values of a HashMap returned as a List?

7条回答
  •  醉酒成梦
    2020-12-08 02:19

    HashMap map = new HashMap();
    map.put (1, "Mark");
    map.put (2, "Tarryn");
    List list = new ArrayList(map.values());
    for (String s : list) {
        System.out.println(s);
    }
    

提交回复
热议问题