Skip to content

codewarrior2000/MapToList2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MapToList2

Code from DZone on Converting Java Maps to Lists

Many thanks to John Thompson, Spring Framework Guru https://springframework.guru

See DZone article: https://dzone.com/articles/converting-java-maps-to-lists

The MapToListConverter contains:

  1. code to convert all the keys of a Map to a Set

  2. code to convert Map values to a List

  3. code using streams (introduced in Java 8), along with some utility classes like Collectors to convert a stream of Map entries to List.

Note: The variable listOfKeys2 has been changed to listOfKeys to correct compile error

public List<Integer> convertMapKeysToListWithStream(Map<Integer,String> map){
    List<Integer> listOfKeys = map.keySet().stream().collect(Collectors.toList());
    return listOfKeys;
}

About

Code from DZone on Converting Java Maps to Lists

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages