I wonder why the Collection.addAll()
method only accepts other Collection
s but not Iterable
s. Why is that?
Any similar method to do that for Iterable
s?
java collection Java iterable interface The Collection interface extends Iterable interface, so all subtypes of Collection implement the Iterable interface. This interface stands to represent data-structures whose value can be traversed one by one. This is an important property.
'Iterator' is an interface which belongs to collection framework. It allows us to traverse the collection, access the data element and remove the data elements of the collection.
Presumably because the Collection
interface was introduced in Java 1.2 whereas Iterable
appeared only in 1.5, and changing the interface would break all existing implementations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With