0

**array of values**

I wants result like this from the array

I'm doing like this and get value in data but how to percentages base total and store in array that i cant do so how to do that.

  1. Arraypercentages value {"18","12"}; // percentage
  2. ArrayIGST value {"00.00","00.00"} // some of values where percentages index is match
  3. ArrayCGST value {"2243.7","1170"}// some of values where percentages index is match
  4. ArraySGST value {"2243.7","1170"}// some of values where percentages index is match

  ArrayList<String> percentageArray = new ArrayList<>();
                        for (int c = 0; c < temp_arraylist.get(j).getListPercantages().size(); c++) {


                            String per = temp_arraylist.get(j).getListPercantages().get(c);// percentages
                            String lcgst = temp_arraylist.get(j).getListcgst().get(c);//cgst
                            String lsgst = temp_arraylist.get(j).getListsgst().get(c);//sgst
                            String ligst = temp_arraylist.get(j).getListigst().get(c);//igst


                            if (percentageArray.contains(per)) {

                            } else {
                                percentageArray.add(per);
                            }

                            for (int e = 0; e < temp_arraylist.get(j).getListPercantages().size(); e++) {
//check where index of percentage is match with current then sum of SGST array index sum and store as same index of percentage array index where it match.
                            }
}
KinG_HP
  • 57
  • 7
  • I'm sorry, but I don't understand what you're asking. – NomadMaker Apr 12 '20 at 17:22
  • i want unique value in percentage array and check with another array where price already calculated with percentages and store in array but i want to sum of that array where percentage match. i can able to make unique array but not able to sum based on percentages . – KinG_HP Apr 13 '20 at 06:05
  • 1
    I'm sorry, but I'm not able to understand this either. To enable others to help you, describe the exact behavior you expected, as well as how that behavior differs from what is happening with your current implementation. Include the exact text of any error messages (including, for any exceptions, the full [stack trace](https://stackoverflow.com/a/23353174) and which line of code is producing it). Please see [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – Ryan M Apr 13 '20 at 09:12
  • https://stackoverflow.com/questions/61191904/hasmap-total-of-keyss-value-sum-in-android – KinG_HP Apr 13 '20 at 16:09
  • I'm asking to like this https://stackoverflow.com/questions/61191904/hasmap-total-of-keyss-value-sum-in-android – KinG_HP Apr 13 '20 at 16:10

1 Answers1

1

First create listog object and set values in listobject like this

 List<Item> list = new ArrayList<Item>();
                        HashMap<String, Double> hashMapsgst = new HashMap<String, Double>();
                        HashMap<String, Double> hashMapigst = new HashMap<String, Double>();
                        for (int c = 0; c < temp_arraylist.get(j).getListPercantages().size(); c++) {
                            String per = temp_arraylist.get(j).getListPercantages().get(c);// percentages
                            String lsgst = temp_arraylist.get(j).getListsgst().get(c);//sgst
                            String ligst = temp_arraylist.get(j).getListigst().get(c);//igst
                            list.add(new Item(per,Double.parseDouble(lsgst),Double.parseDouble(ligst)));
                        }

*Then help of for loop and hashmap *

for (int i=0;i<list.size();i++)
                        {
                            if (hashMapsgst.containsKey(list.get(i).getId()))
                            {
                                Double pricecgst = hashMapsgst.get(list.get(i).getId());
                                Double priceigst = hashMapigst.get(list.get(i).getId());
                                hashMapsgst.put(list.get(i).getId(),pricecgst+list.get(i).getVal() + pricecgst);
                                hashMapigst.put(list.get(i).getId(),priceigst+list.get(i).getVal2() + priceigst);
                            }
                            else
                            {
                                hashMapsgst.put(list.get(i).getId(),Double.valueOf(list.get(i).getVal()));
                                hashMapigst.put(list.get(i).getId(),Double.valueOf(list.get(i).getVal2()));
                            }

                        }

and lastly i get result with key of unique percentages, ans sum of object values

 for (Map.Entry<String, Double> entry : hashMapsgst.entrySet()) {
                            String k = entry.getKey();
                            double v = entry.getValue();
                            double v2 = hashMapigst.get(k);}
KinG_HP
  • 57
  • 7