fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.math.BigDecimal;
  4. import java.util.Arrays;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import java.util.stream.Collectors;
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args)
  13. {
  14. Map<String, List<BigDecimal>> map = new HashMap<>();
  15. map.put("k1", Arrays.asList(new BigDecimal(123), new BigDecimal(55)));
  16. map.put("k2", Arrays.asList(new BigDecimal(123), new BigDecimal(55), new BigDecimal(33)));
  17. Map<String, BigDecimal> result = map.entrySet().stream()
  18. .collect(Collectors.toMap(
  19. Map.Entry::getKey,
  20. e -> e.getValue().stream().reduce(BigDecimal.ZERO, BigDecimal::add))
  21. );
  22.  
  23. System.out.println(result);
  24. }
  25. }
Success #stdin #stdout 0.22s 34044KB
stdin
Standard input is empty
stdout
{k1=178, k2=211}