title: Java 8 groupBy and reduce not summing up values in the column
body: <p>I am trying to use Java8 groupby and reduce feature to sum elements based on grouping but the code doesnt seem to be working for me.</p>
  <p>Here is my data from the Dtolist that I am trying to map and extract in an excel sheet.
  <a href="https://i.stack.imgur.com/Su0yU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Su0yU.png" alt="enter image description here" /></a></p>
  <p>My requirement is that for every DTO object I want this kilometersNumber to be summed up based on groupingBy TruckId. So , the highlighted columns should be having summed up values for same TruckId(**<strong><strong>Contract flotte</strong></strong>)</p>
  <p>This is my DTO:</p>
  <p>'''public class CostsTruckWsDTO implements Serializable {</p>
  <pre><code>private static final long serialVersionUID = 1L;
  
  private String truckId;
  
  private LocalDate period;
  
  private Bigdecimal KilometersNumber;
  
  private String periodStartDate;
  </code></pre>
  <hr />
  <p>Here is the logic::
  ''costsTruckWsDTO.setGroupBy(TruckId.toUpperCase());</p>
  <p>Map&lt;String, List&gt; mapCostsTruck = costsTruck.stream()
  .collect(Collectors.groupingBy(d -&gt; d.getGroupBy().toUpperCase()));
  for (Map.Entry&lt;String, List&gt; entry : mapCostsTruck.entrySet()) {</p>
  <pre><code>        BigDecimal totalKm = entry.getValue().stream().map(x -&gt; x.getKilometersNumber()).reduce(BigDecimal.ZERO,
                  BigDecimal::add);
  </code></pre>
  <p>}
  }''</p>
  <p>But what am getting is value for kilometere is not geeting added as per the screenshot.
  Can anybody pls help me what I am missing here!!!
  Highly appreciate</p>