Skip to main content

#87 - Cases by Type

public Map<String, List<Case>> casesByType(List<Case> cases) {

Map<String, List<Case>> result = new Map<String, List<Case>>();

for (Case c : cases) {

if (c.Type != null) {

if (result.containsKey(c.Type)) {

result.get(c.Type).add(c);

}

else {

result.put(c.Type, new List<Case> { c });

}

}

}

return result;

}

1 Kommentar
  1. 9. Sept., 23:51

    public static Map<String, List<Case>> casesByType(List<Case> cases) {

     

     Map<String, List<Case>> result = new Map<String, List<Case>>();

     

     for (Case c : cases) {

     if (String.isBlank(c.Type)) {

     continue;

     }

     

    result.put(c.Type, (result.get(c.Type) ?? new List<Case>()));

    result.get(c.Type).add(c);

     }

     

    return result;

    }

0/9000