Page 1020 - AP Computer Science A, 7th edition
P. 1020

24. (D) If element is smaller than the last item in the list, it will be compared with every item in the list. Eventually index will be incremented to a value that is out of bounds. To avoid this error, the test in the while loop should be
while(index < list.size() && element.compareTo(list.get(index)) < 0)
Notice that if element is greater than or equal to at least one item in list, the test as given in the problem will eventually be false, preventing an out-of-range error.
































































































   1018   1019   1020   1021   1022