← Unit 4 · all exercises
Saved in this browser only

Add up a list

Return the total of every number in the list. An empty list totals zero.

int sum(java.util.ArrayList<Integer> list)

Solution.java
Loading editor…
Results

Examples

  • Solution.sum(new java.util.ArrayList<>(java.util.List.of(1, 2, 3))) → 6
  • Solution.sum(new java.util.ArrayList<Integer>()) → 0

There are also 2 hidden tests you can't see. Solve the problem, not the examples.