Duplicar posible:
Java: How to convert List to MapArrayList Conversión a Hashmap
tengo arrayList
ArrayList<Product> productList = new ArrayList<Product>();
productList = getProducts(); //Fetch the result from db
Quiero convertir a ArrayList a Hashmap gusta esta
HashMap<String, Product> s= new HashMap<String,Product>();
Por favor, ayúdenme a convertir a HashMap.
¿El 'product' tiene una (s) propiedad (s) única (s) – SimonC
Sí.ProductCode es único – Piraba
Suponga que ** field1 ** es un campo dentro de _ ** Product ** _ clase, por lo que puede hacer esto 'Map urMap = yourList.stream(). Collect (Colectores) .toMap (Product :: getField1, Function.identity())); ' –