I suggest you ...

Please fix answer description

Here is a question with wrong description of the answer.

Given the code. What is the result?
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class TryMe {
public static void main(String args[]) {
List list = new LinkedList<String>();
list.add("one");
list.add("two");
list.add("three");

Collections.reverse(list);
Iterator iter = list.iterator();

for (Object o : iter) {
System.out.print(o + " ");
}
}
}
A) "three two one " is printed
B) "one two three " is printed
C) Nothing is printed
D) Compilation fails
E) An exception is thrown at runtime
Answer: D
The construction for(;) can only iterate over an array or an instance of java.lang.Iterable.

for(:) can't iterate over an instance java.lang.Iterable
It can iterate over java.lang.Collection or an array

1 vote
Vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Anonymous shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

0 comments

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...

Feedback and Knowledge Base