Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

map list to hashmap java8

// convert List<Elem> into a Map<Elem::getName, Elem:getId>
Map<String, String> myMap = elemsList.stream()
  .collect(Collectors.toMap(elem -> elem.getName(), elem -> elem.getId()));
// you may pay attention of elem null cases
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #map #list #hashmap
ADD COMMENT
Topic
Name
5+8 =