My observation of Iterable
is that, while it could be used in preference to Collection
in many places where a stream of data is needed but not the various collection methods like size, it typically isn't within the Java core libraries.
This is just an inference on my part, but it feels like the Java designers are really sticking to Iterable
just being a way to use the enhanced for
statement for a given stream of data, and use Collection
where a bunch of data items are needed, even if Iterable
would be sufficient.
A look at the Javadocs for Iterable
adds weight to this viewpoint, as this is the only thing called out in the class-level Javadocs:
Implementing this interface allows an object to be the target of the enhanced for
statement (sometimes called the "for-each loop" statement).