The basic iterator model of C++'s STL basically consists of a "give me the item at the current position" operator *
, a "go to next item" operator ++
and an a predicate ==
/!=
that is used to check (most of the time) against an end iterator. Of course, there are various further iterators with random access but the most basic one looks like described above.
In contrast, Java has next()
and hasNext()
. Next is roughly equivalent to using ++
and then *
. hasNext()
is something like comparison against end. Why has Java not adopted the C++ model (of course, it doesn't have operator overloading so it must mimic it by functions)? Especially, why was comparison against an end iterator dropped for a hasNext()
method? I find it often harder to write iterators in Java than in C++ because the logic behind next()
and hasNext()
is often more complex than the one in the C++ operators.