Enrol to start learning
Reading is open to everyone. Enrolling is free, and it is what unlocks the audio lessons, practice tests and progress tracking.
15.6. Iterating Over Collections
This section
Practice test
12 questions on this section. Wrong answers show you what to read again.
Sign up to take itWhole chapter
Revision test
Mixed questions from across the chapter. Your answers get marked.
Sign up to take itQuick
Flashcard drill
4 cards from this lesson. Good the night before a test.
Try these first
- 1.
What can the enhanced for-loop be used for?
Hint
Think of a scenario where you just want to read elements.
- 2.
What does
hasNext()do in an Iterator?Hint
Recall the method’s purpose in the iteration process.
- 3.
Which method allows you to avoid managing indices while iterating?
- Iterator
- Enhanced For-Loop
- ListIterator
Hint
Consider which method is specifically designed to streamline coding.
- 4.
True or False: You can use the
remove()method with every iteration method.- True
- False
Hint
Think about what happens when you try to modify a collection directly.
- 5.
Write a program that uses an enhanced for-loop to print even numbers from an array of integers.
Hint
Think of how to structure your loop to include a condition for even numbers.
- 6.
Demonstrate how to safely remove elements from an ArrayList while iterating using an Iterator.
Hint
Remember, `remove()` must be called on the iterator, not the list directly.
Exercises
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
4 more questions available
Enrol freeQuiz
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
2 more questions available
Enrol freeChallenge Problems
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting