Not being able to for-loop over an Iterator, as opposed to an Iterable,
is also incredibly frustrating. I start with something like this:
for (String s: someCollectionOfStrings) {
fooBarDoStuff();
doSomethingOnlyForTheLastElement(); // needs a guard
}
And then i [sic] realsie that i [sic] can't do that - i [sic] have to rewrite the loop as
a while loop. Like:
Iterator<String> it = someCollectionOfStrings.iterator();
while (it.hasNext()) {
s = it.next()) {
fooBarDoStuff();
if (it.hasNext()) doSomethingOnlyForTheLastElement();
}
Which feels much less cohesive and more clunky to me.
If you want to use a traditional three-part for loop, you have to do
something bonkers like:
String s;
for (Iterator<String> it = someCollectionOfStrings.iterator();
it.hasNext() && ((s = it.next()) != null)

{
fooBarDoStuff();
if (it.hasNext()) doSomethingOnlyForTheLastElement();
}