Chapter 7. The for/in Statement
Ditching Iterators
Iterating over Arrays
Iterating over Collections
Avoiding Unnecessary Typecasts
Making Your Classes Work with for/in
Determining List Position and Variable Value
Removing List Items in a for/in Loop
One of the coolest things about Tiger is that it offers so many new language
features. When Java 1.3 and 1.4 were released, they had some
new goodies, but most of the changes were either implementation issues
(like all the Collection class restructuring), or things you didn't use everyday
(like proxies). Tiger is very different, thoughyou get to write new,
funky-looking code, and that's about as good as it gets for hardcore
developers.This chapter examines one of these
new language features, the for/in
loop. This name is a bit deceiving, as the loop never uses the in keyword;
as a result, it's often
called enhanced
for
, and even sometimes
foreach
. No matter what you call it, though, it's mostly a convenience
functionit doesn't make Java do anything particularly new, but it does
save some keystrokes. If you're an emacs or vi guy, that's pretty nicethe
less you type, the more advanced a programmer you must be, right?