For educational purposes, it was necessary to independently implement linked lists and make it possible to bypass through foreach. As I understand it, you need to implement Iterable in the collection and create a class implementing Iterator. The question is what exactly to do in the Iterable interface method.
public void forEach(Consumer action) and Iterator interface method
public void forEachRemaining(Consumer<? super E> action) throws NullPointerException
Iterableyou need, of course, to implement aniterator()method that returns - what? - iterator. - VladDIterable.forEachandIterator.forEachRemainingaredefaultmethods, i.e. they have an implementation in the interface (the help describes the expected behavior). - zRrr