Java: why does Collection.addAll can not accept Iterables?

Others have answered the "why" extensively.

Any similar method to do that for Iterables?

In Java 8 you don't need addAll any more:

Collection<X> coll = ...;
Iterable<X> it = ...;
it.forEach(coll::add); // coll.addAll(it);

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.


When in doubt, always check Guava (or Commons):

  • Guava: Iterables.addAll
  • Commons Collections: CollectionUtils.addAll