hi
what is the differnce between Iterable & Iterator
please explain it with example if any body can
thankyou
Printable View
hi
what is the differnce between Iterable & Iterator
please explain it with example if any body can
thankyou
hi, thanks for reply
i know the documentation will describe it,i want to know what is the differnce between Iterable & Iterator means where to use iterator with iteratable
thanks
An Iterable is able to give you an Iterator; note that other classes may be able to do the same. If you have an Iterable you can use an advanced for loop because the compiler knows about Iterables. There is nothing more to say about Iterables in combination with Iterators.
kind regards,
Jos
This is a classic example of an interface vs a concrete class. Usually object types ending in 'able' (Iterable, Comparable, etc...) are objects that implement some interface which guarantees a certain collection of methods will be available. An Iterator itself is a concrete object which is use for the iterations. As JosAH said, a class which implements Iterable is guaranteed to be iterable (it comes with methods to perform iteration - return an Iterator), and can be referred to by the generic interface type of Iterable.