Eventuali duplicati:
Java: How to convert List to MapConversione ArrayList a HashMap
ho arrayList
ArrayList<Product> productList = new ArrayList<Product>();
productList = getProducts(); //Fetch the result from db
voglio convertire a ArrayList per hashmap Ti piace questa
HashMap<String, Product> s= new HashMap<String,Product>();
Per favore aiutami a convertire in HashMap.
Fa 'Product' hanno una proprietà unica (i)? – SimonC
Yes.ProductCode è univoco – Piraba
Si supponga che ** field1 ** sia un campo all'interno della classe _ ** Product ** _, quindi è possibile eseguire questa operazione 'Map urMap = yourList.stream(). Collect (Collectors .toMap (Product :: getField1, Function.identity())); ' –