0Pricing
Java Academy · Lesson

Iterators & Enhanced for

Traverse collections with Iterator and enhanced for. Learn safe removal during iteration and common pitfalls.

Overview

Iterator gives step-by-step control to walk through a collection. Enhanced for (for-each) is shorter and clean for reading elements. Use Iterator when you need to remove safely during traversal.

Iterator vs for-each

  • Iterator: use when you may remove items or need fine control.
  • Enhanced for: best for read-only loops.
  • Never structurally modify the collection inside enhanced for.

All lessons in this course

  1. List & Set Overview
  2. Iterators & Enhanced for
  3. Collections Utilities
← Back to Java Academy