Stack Exchange
How would I add values based on one parameter in Custom Array List?
How would I add up values in Custom Array list having bean class consisting variables  itemcode (String) , cases(int) , packs (int) , pcs (int)
I have more than one value saved in Array list as 
 {code1 , 3,4,5}  
    {code2 , 3,5,5}  
    {code3 , 3,2,5}  
    {code3 , 1,4,2}  
    {code1 , 3,3,5}  
    {code3 , 3,4,5}  
    {code2 , 3,8,5}  
    {code2 , 3,4,6}

In Such case I need result as 
{code1 ,6,7,10 }
{code2 ,9,17,16 }
{code3 ,7,10,12}  


Show some actual code please. And explain where you're stuck exactly.

I was checking out this example http://stackoverflow.com/questions/25699131/sum-value-of-class-objects-property-in-arraylist

@Yatin: What's preventing you from using the answers given in the question you link to?

I don't know exactly how your bean looks, but with a HashMap and loop you can "group by and sum" as you need.
It could look something like this:
public static List<BeanClass> sumPerItemCode
    (List<BeanClass> list) {

    Map<String, BeanClass> map = new HashMap<>();

    for (BeanClass p : list) {
        String code = p.getItemCode();
        BeanClass aggregatedItem = map.get(code);
        if (aggregatedItem == null) {
            aggregatedItem = new BeanClass(code, 0,0,0);
            map.put(code, aggregatedItem);
        }

        aggregatedItem.setCases(aggregatedItem.getCases() + p.getCases());
        aggregatedItem.setPacks(aggregatedItem.getPacks() + p.getPacks());
        aggregatedItem.setPcs(aggregatedItem.getPcs() + p.getPcs());
    }
    return new ArrayList<BeanClass>(map.values());
}


I suggest you to use Map instead of List.
Map replace the value of existing value if key is same.
what you have to do is first check is key is available get that value and do addition then again store it in Map using same key.
`

Try with it - 
ArrayList<String> list = new ArrayList<String>();
list.add("code1");               //itemcode
list.add(String.valueOf(100));   //cases
list.add(String.valueOf(150));   //packs
list.add(String.valueOf(200));   //pcs

And to get data fron arrayList - 
String itemcode  = list.get(0);              //code1
int cases = Integer.parseInt(list.get(1));   //100
int packs = Integer.parseInt(list.get(2));   //150
int pcs = Integer.parseInt(list.get(3));     //200

But i always suggest to use Map instead of ArrayList for this type of scenario with same mechanism. Because Map can store data as key value pair. 

Create a Bean Class Like thatpublic class BeanClass{public String code;public int integerOne;public int integerTwo;public int integerThree;public BeanClass(String code,int integerOne,int integerTwo,int integerThree){this.code=code;this.integerOne=integerOne;this.integerTwo=integerTwo;this.integerThree=integerThree}}In Main ClassArrayList<BeanClass>beanclassArrayList=new ArrayList<>();for(int i=0;i<YourArrray[].length();i++){BeanClass beanClass=new BeanClass(codeArray[i],integerOneArray[i],integerTwoArray[i],integerThreeArray[i]);beanclassArrayList.add(beenClass);}

Would it be possible for you to format your answer a bit? It's completely unreadable in its current state.

check it@Henrik
