1Z0-811 • Practice Test 33
Free 1Z0-811 practice test — 15 questions with explanations. Set 33. No signup required.
A developer is writing a batch processing application that reads a list of orders and processes each one. The orders are stored in an array of Order objects. The processing logic is complex and involves multiple conditional checks. The developer uses a for-each loop to iterate over the array. However, during testing, the application throws an IndexOutOfBoundsException when processing orders that have a status of "CANCELLED". The developer wants to skip the processing of cancelled orders but still record that the order was skipped in a log. The current code is:
for (Order order : orders) {
if (order.getStatus().equals("CANCELLED")) {// Skip
}// process order process(order); log(order);
}The developer considers four options:
A. Change the for-each loop to a traditional for loop with an index and increment only when order is not cancelled. B. Add a continue statement inside the if block. C. Change the if condition to check for non-cancelled orders and wrap only the process(order) call inside the if block, leaving log(order) outside. D. Use a while loop with an iterator and remove cancelled orders from the array.
Which option best solves the problem without modifying the array and while still logging all orders?
Choose an answer to begin — your selection is scored in the full session.
15 questions · instant feedback and full explanations after every question.