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 + " ");
}
}
}
This question is from SCJP , i have problem in understanding iterator and iterable.
I know iterator is an interface with iterator method. Why we cant use for each loop in case of iterator? Compiler says: can only iterate over an array or an instance of java.lang.iterable. what is this? i tried alot to search but didnt get answer
Please Reply