For an assignment, we had to write a method sum that expects a List as a parameter. The method returns an int representing the sum of the integers in the list.
Would the code turn out to be:
public int getSum (List <Integer> list) {
int sum = 0;
for (int i = list)
sum = sum + i;
return sum;
}
I'm confused on when to use Integer vs int in this scenario. Thanks in advance!
Edit: If possible, could you guys edit my code?