Loops Flashcards

1
Q

Which interface must be implemented to allow an object to be iterated by a “for-each” loop?

A

Iterable<T>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the equivalent code for: Iterable.forEach(Consumer action)?

A
for(var e : obj) {
action.accept(e);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. What is the syntax of a for loop?
  2. Can a for loop have multiple initializers?
  3. Is “init” reinitialized for each iteration?
A
  1. for(init; expression; inc) {...}
  2. Yes
  3. No, only initialized once
How well did you know this?
1
Not at all
2
3
4
5
Perfectly