05: Arrays and Lists
Submit this homework using Gradescope. You can type up your answers, or write legibly and scan them. Do not attempt to submit a paper copy in class, as it will not be accepted.
For each question, write the method assuming that it’s part of the ArrayStringList
we started in lecture. The code is in the notes, linked to from the Schedule page, if you missed class.
A. (1 point) Write a public void set(int i, String s)
method that sets the element of the list at index i
to the value s
. That is, it should overwrite the existing element at i
. Be sure to handle exceptional conditions appropriately.
B. (1 point) Write a public int indexOf(String s)
method that searches the list for the first occurrence of a value equivalent to s
(be careful with what kind of equality you use!), and returns its index. Return -1
if the value is not found.