Java Code Completion Medium +20 XP
Enhanced For Loop
Complete the enhanced for loop.
JavaFill in the blank
List<String> names = Arrays.asList("Alice", "Bob");
___ (String name : names) {
System.out.println(name);
}Type the missing code
Show answer and explanation
Answer: for
The enhanced for loop (for-each) uses the syntax: for (Type variable : collection).
Hint: Which keyword starts a loop?
What this challenge tests
Code Completion in Java: loops, collections.