Thanks for the reply, and sorry for not being very clear in my first post.
So far I have:
public class MyClass implements Iterable<AnotherClass>, Iterator<AnotherClass> {
count = 0;
AnotherClass[] collection;
public MyClass(){
}
//constructors and other stuff here
...
public Iterator<AnotherClass> iterator() {
return this;
}
public boolean hasNext() {
return count < collection.size();
}
public AnotherClass next() {
if(count == collection.size()){
throw new NoSuchElementException();
}
return collection[count];
}
public void remove() {
throw new UnsupportedOperationException();
}
And according to the example I've read on another site, this should work. What I don't understand though, is when/where should i reset the count variable? (I realize the class I've presented is pretty useless, I'm using it merely as an example) If I iterate through the collection once, the count variable will be incremented until it reaches the end of the collection. And if I want to iterate through it again, it seems to me I'll have a problem :P