Manipulating a group of objects is something every Java developer does almost every day. In those situations, a lot of developers turn to some concrete collections such as ArrayList
or HashSet
without second thought. More experienced ones try to avoid accepting concrete classes and use some interface like java.util.List
, and even more experienced ones turn to java.util.Collection
. But sometimes we don’t need a collection at all, only the ability to iterate over some objects and for those needs, Iterable
is beautiful! Let’s see how to improve your programs by using java.lang.Iterable<T>
.