186k views
2 votes
5.Consider the following code snippet:ArrayList arrList = new ArrayList();for (int i = 0; i < arrList.size(); i++){ arrList.add(i + 3);}What value is stored in the element of the array list at index 0? Think carefully about this.A. 0B. 3C. 6D. None

User Mohmmad S
by
8.6k points

1 Answer

6 votes

Answer:

The answer to this question is the option "D".

Explanation:

  • In the given question code we use the array list that does not store any value in the index 0, because for adding elements in the list, we use add function.
  • In this function parameter, we pass the value that is "i+3". Which means the value of i is increased by 3.
  • In option A, B and C we do not assign any value in the add function. so, it not correct.

That's why the correct answer to this question is the option "D".

User MLSC
by
7.3k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.