Possible Duplicate:
Java: How to convert List to Map
I have arrayList
ArrayList<Product> productList = new ArrayList<Product>(); productList = getProducts(); //Fetch the result from db I want to convert to ArrayList to HashMap Like this
HashMap<String, Product> s= new HashMap<String,Product>(); Please help me how to convert to HashMap.
Producthave a unique property(ies)?Map<String, Product> urMap = yourList.stream().collect(Collectors.toMap(Product::getField1, Function.identity()));