You have two classes:
Account: number: String, balance: Long
Transaction: uuid: String, sum: Long, account: Account
Both classes have getters for all fields with the corresponding names (getNumber(), getSum(), getAccount() and so on).
I need to calculate sum of transaction for every account, but exactly not by Account, but grouping by Account.number
I make it like this:
Map<Account, Long> totalSumOfTransByEachAccount =
transactions.stream()
.collect(Collectors.groupingBy(Transaction::getAccount, Collectors.reducing(0, Transaction::getSum, Long::sum)));
But I need map with String key - Account.getNumber()
Map<String, Long> totalSumOfTransByEachAccount =
transactions.stream()
.collect(Collectors. ??????)
Can anyone help me?