Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

You can ease the code by always retrieving the List value in the for loop, then if it is null create a new one and add it to your Map, otherwise add the value to the list.

for (int i = 0; i < records.length; i++) { List<String> value = sfFundIdsByContact.get(breakdown.getSalesConnect__Contact__c()); if (value == null) { value = new ArrayList<String>(); sfFundIdsByContact.put(breakdown.getSalesConnect__Contact__c(), value); } value.add(breakdown.getId()); } 

As a recommendation, change the definition of

LinkedHashMap<String, ArrayList<String>> sfFundIdsByContact 

to

Map<String, List<String>> sfFundIdsByContact 

Refer to What does it mean to "program to an interface"?What does it mean to "program to an interface"?

You can ease the code by always retrieving the List value in the for loop, then if it is null create a new one and add it to your Map, otherwise add the value to the list.

for (int i = 0; i < records.length; i++) { List<String> value = sfFundIdsByContact.get(breakdown.getSalesConnect__Contact__c()); if (value == null) { value = new ArrayList<String>(); sfFundIdsByContact.put(breakdown.getSalesConnect__Contact__c(), value); } value.add(breakdown.getId()); } 

As a recommendation, change the definition of

LinkedHashMap<String, ArrayList<String>> sfFundIdsByContact 

to

Map<String, List<String>> sfFundIdsByContact 

Refer to What does it mean to "program to an interface"?

You can ease the code by always retrieving the List value in the for loop, then if it is null create a new one and add it to your Map, otherwise add the value to the list.

for (int i = 0; i < records.length; i++) { List<String> value = sfFundIdsByContact.get(breakdown.getSalesConnect__Contact__c()); if (value == null) { value = new ArrayList<String>(); sfFundIdsByContact.put(breakdown.getSalesConnect__Contact__c(), value); } value.add(breakdown.getId()); } 

As a recommendation, change the definition of

LinkedHashMap<String, ArrayList<String>> sfFundIdsByContact 

to

Map<String, List<String>> sfFundIdsByContact 

Refer to What does it mean to "program to an interface"?

Source Link
Luiggi Mendoza
  • 85.9k
  • 16
  • 160
  • 354

You can ease the code by always retrieving the List value in the for loop, then if it is null create a new one and add it to your Map, otherwise add the value to the list.

for (int i = 0; i < records.length; i++) { List<String> value = sfFundIdsByContact.get(breakdown.getSalesConnect__Contact__c()); if (value == null) { value = new ArrayList<String>(); sfFundIdsByContact.put(breakdown.getSalesConnect__Contact__c(), value); } value.add(breakdown.getId()); } 

As a recommendation, change the definition of

LinkedHashMap<String, ArrayList<String>> sfFundIdsByContact 

to

Map<String, List<String>> sfFundIdsByContact 

Refer to What does it mean to "program to an interface"?