πŸ“’ Too many exams? Don’t know which one suits you best? Book Your Free Expert πŸ‘‰ call Now!

  • google app store apple app store
  • βœ–

      Question

      A programmer is trying to debug an issue where an

      `ArrayList` (or equivalent dynamic array) in their Java/Python code unexpectedly throws anΒ  `IndexOutOfBoundsException` during an iteration. Which debugging technique would be most effective to pinpoint the exact cause?Β 
      A Setting a breakpoint at the start of the program and running it. Correct Answer Incorrect Answer
      B Using print statements to display the list size and current index inside the loop. Correct Answer Incorrect Answer
      C Commenting out the entire loop to see if the error disappears. Correct Answer Incorrect Answer
      D Changing the `ArrayList` to a `LinkedList` without further investigation. Correct Answer Incorrect Answer

      Solution

      An `IndexOutOfBoundsException` during iteration strongly suggests an issue with the loop bounds or the index being used. Printing the list size and the current index (`i`) within the loop will immediately show when `i` exceeds or equals the list's valid index range.

      Practice Next
      More IT DBMS Questions
      ask-question