Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose indList is an indexed list that contains seven elements. Suppose element

ID: 3803112 • Letter: S

Question

Suppose indList is an indexed list that contains seven elements. Suppose element is an Object that is not already on the list. For each of the following method invocations, indicate whether they would result in the IndexOutOfBoundsException being thrown. Each part of this question is independent.
a. indList.add(6. element)
b. indList.add(7. element)
c. indList.set(6. element)
d. indList.set(7. element)
e. indList.remove(element)
f. indList.get(element)
g. indList.remove(-1)
h. indList.remove(0)
Suppose indList is an indexed list that contains seven elements. Suppose element is an Object that is not already on the list. For each of the following method invocations, indicate whether they would result in the IndexOutOfBoundsException being thrown. Each part of this question is independent.
a. indList.add(6. element)
b. indList.add(7. element)
c. indList.set(6. element)
d. indList.set(7. element)
e. indList.remove(element)
f. indList.get(element)
g. indList.remove(-1)
h. indList.remove(0)

a. indList.add(6. element)
b. indList.add(7. element)
c. indList.set(6. element)
d. indList.set(7. element)
e. indList.remove(element)
f. indList.get(element)
g. indList.remove(-1)
h. indList.remove(0)

Explanation / Answer

a. indList.add(6, element) = No
since 6th index is will be under 7 elements of list

b. indList.add(7, element) = Yes
because, 7th index will be be present as indexing starts from 0

c. indList.set(6, element) = No
since 6th index is will be under 7 elements of list

d. indList.set(7, element) = Yes
because, 7th index will be be present as indexing starts from 0

e. indList.remove(element) = Yes
because element might not be an index present in the list

f. indList.get(element) = Yes
because element might not be an index present in the list

g. indList.remove(-1) = Yes
because -1 is an invalid index, indexing starts from 0

h. indList.remove(0) = No
because indexing started from 0 and 0th element can be removed from list