Can Idea convert old-style for loops to 'for each'?

I'm looking for the refactoring or intention to convert an old-style for
loop
for (Iterator i = ...;i.hasNext();) { }
into the 5.0-style
for ( ... : ...) { }

Does such a thing exist and I've just missed it? Should I file an SCR?

R

2 comments


There is an inspection for finding for-loops which can be converted to for-each. I believe it's under the "Verbose or redundant code constructs" category (not the best place, I'm afraid). Turn that inspection on in the Settings/Error panel, and for loop that can be converted will be highlighted, and a quickfix for doing the conversion will be available. Alternately, you can use the batch inspection tool to convert all of your for-loops in one swell foop.

--Dave Griffith

0

Please sign in to leave a comment.