Question

Consider an Iterator<Integer> variable called iter for a structure containing the following data: 0, 1, 2,...

Consider an Iterator<Integer> variable called iter for a structure containing the following data: 0, 1, 2, 3, 4, 5. What will the resulting sequence be if the following methods are called:

iter.next();

iter.next();

iter.remove();

iter.remove();

2, 3, 4, 5

0, 1, 4, 5

0, 3, 4, 5

An IllegalStateException will occur


0 0
Add a comment Improve this question Transcribed image text
Answer #1

The resulting sequence be 0, 1, 4, 5

This is because after two iter.next(); the iterator is at 2 then iter.remove(); removes 2 and the iterator goes to 3 and iter.remove(); removes 3.
So, the output sequence is 0,1,4,5.


If the answer helped then please upvote, it means a lot.
And for any queries feel free to comment.

Add a comment
Know the answer?
Add Answer to:
Consider an Iterator<Integer> variable called iter for a structure containing the following data: 0, 1, 2,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT