Thursday, September 5, 2013

When an object to be the target of the "foreach" statement?


for-each loop:



Implementing Iterable interface allows an object to be the target of the "foreach" statement.

java.lang
Interface Iterable<T>



All Known Subinterfaces:
BeanContextBeanContextServicesBlockingDeque<E>, BlockingQueue<E>, Collection<E>, Deque<E>, List<E>, NavigableSet<E>, Queue<E>, Set<E>, SortedSet<E>


So we can Iterate List, Set, SortedSet, Collection..etc Objects.


sources :http://docs.oracle.com/javase/6/docs/api/java/lang/Iterable.html

No comments:

Post a Comment