1). Iterator is an iterator class, while Iterable is to use foreach to iterate as long as the interface is implemented.
2). Iterable encapsulates the Iterator interface. As long as the Iterable interface class is implemented, you can use the Iterator iterator.
3). Collection Collection, List, and Set are all implementation classes of Iterable, so they and their subclasses can be iterated using foreach.
4). The core methods of Iterator and next(), hasnext(), and remove() all depend on the current location. If these collections directly implement Iterator, they must include a pointer to the current iterator position. When the set is passed between methods, the current position is agnostic, so the value after next() is also unknown. However, when implementing Iterable, it will not be the case. Each call returns an iterator starting from scratch, and each iterator does not affect each other.
The above java collection_A brief discussion on the difference between Iterable and Iterator is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.