ArrayList<MyObject> list=new ArrayList<MyObject>();
HashMap<Integer,ArrayList<MyObject>> hash=new HashMap<Integer,ArrayList<MyObject>>();
for(MyObject elem:list)
{
ArrayList<MyObject> tmp=null;
if((tmp=hash.get(elem.getId()))==null)
{
tmp=new ArrayList<MyObject>();
hash.put(elem.getId(),tmp);
}
names.add(elem);
}
source
share