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

后端 未结 7 1147
春和景丽
春和景丽 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:31

    Basically you should not mess the question with answer, because it is confusing.

    Then you could specify what convert mean and pick one of this solution

    List keyList = Collections.list(Collections.enumeration(map.keySet()));
    
    List valueList = Collections.list(Collections.enumeration(map.values()));
    

提交回复
热议问题