Skip to content

Instantly share code, notes, and snippets.

View grommitz's full-sized avatar

Martin Charlesworth grommitz

View GitHub Profile
@grommitz
grommitz / gist:9f0fdd38c10a0bb61e88
Last active December 20, 2017 23:23 — forked from raoulDoc/gist:fd997c5248285f903d65
fancy uses of collect in java 8 streams - done at a meetup with Raoul Gabriel Urma
@Test
public void mapEachTraderToTheSumOfTheirTransactions() {
//TODO: Create a Map<String, Integer> that maps each Trader's name with the sum of all its Transactions’ values
Map<String, Integer> mapNameToSumValue = new HashMap<>();
mapNameToSumValue =
transactions.stream()
.collect(groupingBy(transaction -> transaction.getTrader().getName(),
summingInt(transaction -> transaction.getValue())