I want to store objects of class from arraylist to hashmap, one key may contain multiple objects, how to do that
here is my code,
Map<Integer, classObject> hashMap = new HashMap<Integer, classObject>();
for(int i=0; i<arraylist.size(); i++)
{
sortID = arraylist.get(i).getID();
if(!hashMap.containsKey(sortID))
{
hashMap.put(sortID, arraylist.get(i));
}
hashMap.get(sortID).add(arraylist.get(i)); //i got error in add method
}
give any idea to add classobjects in hashmap for same key value...