I have this piece of code :
Map<String, BillingAccount> billingAccountsMap = new HashMap<>();
for (BillingAccount ba : billingAccounts) {
if (ba.getBillingAccountIdentifier() != null && ba.getBillingAccountIdentifier().getIdentifier() != null) {
billingAccountsMap.put(ba.getBillingAccountIdentifier().getIdentifier(), ba);
}
}
All I want is to rewrite it in a functional way with Java Stream API and collect(Collectors.toMap())
, but I am a bit perplexed with the null
cases.
I am using Java 11.