June 2018
Beginner
722 pages
18h 47m
English
Every collection that implements the Collection interface (which extends the Iterable interface) can be iterated over using the enhanced for statement discussed in Chapter 10, Control Flow Statements. Here is an example:
List list = new ArrayList();list.add(null);list.add(1);list.add("ss");list.add(new A());list.add(new B());for(Object o: list){ //code that does something with each element }
The Iterable interface also adds the following three methods to the List interface:
Read now
Unlock full access