Skip to content
Learn Netverks

Lesson

Step 21/36 58% through track

loops-iterators

Loops and iterators

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Loops and iterators: the syntax, APIs, and habits you need before advancing in Java.

Frameworks like Laravel are OOP-first—classes, visibility, and inheritance show up in every code review.

You will apply Loops and iterators in contexts like: Spring Boot APIs, banking systems, Android (with Kotlin), and batch/data pipelines on the JVM.

Write Java with a public class (lessons use Main), click Run on server—the dev runner runs javac then java; fix compile errors from stderr (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Beyond indexed for loops, Java collections implement Iterable—enhanced for-each and explicit Iterator support safe removal during iteration (with iterator's remove, not collection's while looping).

Iterator pattern

Iterator<String> it = items.iterator();
while (it.hasNext()) {
    String s = it.next();
}

forEach (Java 8+)

items.forEach(s -> System.out.println(s));

Important interview questions and answers

  1. Q: Can you remove during enhanced for?
    A: Not safely with list.remove(i)—use iterator.remove or removeIf.
  2. Q: Iterable vs Iterator?
    A: Iterable provides iterator(); Iterator traverses elements.

Self-check

  1. Which loop syntax works on any Iterable?
  2. Why is concurrent modification dangerous?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Iterator remove safe?
  • for-each on Map how?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump