views:

52

answers:

1

Quick question really:

I've seen in bits of code in the past where the code could call count() on a object that implements Iterator, for custom Iterator classes.

I've written a class that implements Iterator and works fine in a foreach loop, but I was just wondering if there was an extra class I had to extend or function I had to implement in order for count() to work on my class, to return a value I want.

+6  A: 

I don't have much experience with Iterators, but this looks like what you're looking for:

The Countable interface

Classes implementing Countable can be used with the count() function.

Pekka
That's correct.
Gordon
Yes that's right, I think I need to improve my Googling skills, I wasn't able to find this. Thanks again.
wiggles