I have a class looking something like the code below. It implements the Iterable<T>
iterface, which it uses to provide iteration capabilities over its contained array.
I have been in the habit of rolling my own trivial iterator to iterate over arrays. I just realized, however, that at least for spliterators, you can get an acceptable default implementation by calling Arrays.spliterator(array)
. Is there a similar default implementation of an ordinary Iterator<T>
over an array of T
?
public class MyClass implements Iterable<ContainedClass>
{
...
private final ContainedClass[] array;
...
//
// INTERFACE: Iterable<ContainedClass>
//
@Override
public Iterator<ContainedClass> iterator() {
return ??? // I want to return a default implementation, not my own!
}
@Override
public Spliterator<ContainedClass> spliterator() {
return Arrays.spliterator(array);
}
}