Answer:
Code 1:- for (int i = 0; i < list1.size(); i++) sum += list1[i];
It will run perfectly and add the elements to the sum variable.The sum will totally depend that the sum is within the range of double variable.If it is out of range then there will be error out of bounds.
Code 2:- for (int i = 0; i < list2.getSize(); i++) sum += list2.get(i);
This code will give syntax error because there is no getSize() method.For linked list there is size() method which determines the size of the list.