Can we write our own iterator in Java?
The best reusable option is to implement the interface Iterable and override the method iterator(). Here’s an example of a an ArrayList like class implementing the interface, in which you override the method Iterator(). import java.util.Iterator; public class SOList<Type> implements Iterable<Type> { private Type[] arrayList; private int currentSize; public SOList(Type[] newArray) { this.arrayList = newArray; … Read more