I need some help mapping a Map<String, List<Fee>> with a List<FeeRequest>.
Fee object looks like this:
private String feeCode;
FeeRequest objects looks like this:
private String feeCode;
private String debtorAccount;
So what I need is to map:
String debtorAccount(from map) -> debtorAccount(from List)
feeCode(from List from map) -> feeCode(from List)
I want to try not to use foreach, but instead learn to properly use .stream().map() features.
What I've managed to do:
Map<String, List<Fee>> feeAccounts is parsed from another method.
List<FeeRequest> feeRequests = feeAccounts.entrySet().stream().map(feeAcc -> {
FeeRequest request = new FeeRequest();
request.setDebtorAccount(feeAcc.getKey());
request.setFeeCode(...);
return request;
}).collect(Collectors.toList());
I think that my approach is bad, but I don't know how to make it work. I tried looking at some examples but they're too basic. So I would be glad to get any help. Thanks!
I think that my approach is bad- why?List<Fee>withfeeAcc.getValue(). It's not clear what you wish to do with it, though.FeeRequest.setFeeCode(Fee.getFeeCode()). Feecodes from one list map with feecodes from anotherListofFeeinstances. Which one of them do you wish to use? Or do you want to create multipleFeeRequestinstances (one for eachFeeinstance)?