Java Collections – Why Does Iterable Sit in java.lang?

apicollectionsjavapackages

As per the below diagram, except for interface Iterable, all the remaining constructs (interface / class / abstract class) sit in same package java.util

enter image description here

 

Why does Iterable sit in java.langpackage?

Note: The intention is to understand the packaging aspect of java programming.

Best Answer

As explained in its javadoc, the purpose of Iterable is to support particular language syntax:

Implementing this interface allows an object to be the target of the "foreach" statement

As such, it belongs to the lang package, which

Provides classes that are fundamental to the design of the Java programming language.


Other classes at the diagram belong to JCF and hence, are in the util package which

Contains the collections framework...