How to convert List to Map?
With java-8, you’ll be able to do this in one line using streams, and the Collectors class. Map<String, Item> map = list.stream().collect(Collectors.toMap(Item::getKey, item -> item)); Short demo: import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class Test{ public static void main (String [] args){ List<Item> list = IntStream.rangeClosed(1, 4) .mapToObj(Item::new) .collect(Collectors.toList()); //[Item [i=1], Item … Read more