In Java, how does one get the values of a HashMap returned as a List?
Solution using Java 8 and Stream Api:
private static List createListFromMapEntries (Map map){
return map.values().stream().collect(Collectors.toList());
}
Usage:
public static void main (String[] args)
{
Map map = new HashMap<>();
map.put(1, "one");
map.put(2, "two");
map.put(3, "three");
List result = createListFromMapEntries(map);
result.forEach(System.out :: println);
}