[java] Converting ArrayList to HashMap

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.

This question is related to java

The answer is


[edited]

using your comment about productCode (and assuming product code is a String) as reference...

 for(Product p : productList){
        s.put(p.getProductCode() , p);
    }

Using a supposed name property as the map key:

for (Product p: productList) { s.put(p.getName(), p); }