I have a list see below (orginalList), this coming from an oracle database, and contains elements
I would to filter this list and put the result into a new list like the list below (newList) as you can see, the BMW showing three times, mercedes two times, Opel one time and have the same dID, so I would like to put BMW into one row on the basis of dID , and one row for two mercedes and one row for the Opel. and the count the total, like below:
Who can help and please with example. Thanks
Code:
orginalList= [info:"F123",brand:"BMW",dID:3,price:40000,
info:"F100",brand:"BMW",dID:3,price:40000,
info:"F200",brand:"BMW",dID:3,price:40000,
info:"C344",brand:"mercedes",dID:5,price:50000,
info:"C354",brand:"mercedes",dID:5,price:50000,
info:"D355",brand:"Opel",dID:7,price:30000]
Code:
newList= [infos:"F123_F100_F200",brand:"BMW",dID:3,price:40000,total:3,
infos:"C344_C354",brand:"mercedes",dID:5,price:50000,total:2,
infos:"D355",brand:"Opel",dID:7,price:30000,total:1]
I tried some thing like the below but this doesnt give the result I want:
List<Export> result = []
for (Object y : GetUniqueValues(orginalList.dID)){
Export export = new InvoiceExport()
export.dID = y
result << export
}
public static ArrayList GetUniqueValues(Collection values)
{
return new ArrayList(new HashSet(values));
}
Comment