Which condition visits every valid index of list?
i < list.size()i <= list.size()i < list.lengthi <= list.length()size() - 1, so an indexed traversal uses < against list.size().
Explanation
An ArrayList reports its length with list.size() and reaches its elements with list.get(i). Because counting starts at 0, the last stored element sits at size() - 1, and a strict < is exactly what stops the loop there.
- B is not correct: Using
<=lets the loop run one step past the last element, so its final access islist.get(list.size()), an index where no element exists. - C is not correct:
lengthwithout parentheses is how an array reports its length, as inarray.length; anArrayListreports its length throughsize()instead. - D is not correct: This mixes the wrong length name with the wrong comparison, so even if the length were read correctly the
<=would still push the traversal past the final valid index.