java - Eclipse refactor Iterator/while to foreach -
does knows if there simple way of refactoring code use foreach iterate on collection instead of while/iterator combo?
example:
i have:
iterator<myobject> iterator = list.iterator(); while (iterator.hasnext()) { myobject myobject = iterator.next(); // stuff }
and want:
for (myobject myobject : list) { // stuff }
and yes, understand won't performance improvements. want less verbose , because fancy :)
suppose occurrence of iteration code similar example, try using find , replace following regular expression.
find:
iterator<([a-za-z0-9_]{1,})> [a-za-z0-9_]{1,} = ([a-za-z0-9_]{1,})\.iterator\(\);\r[\t]{1,}while \(iterator\.hasnext\(\)\) \{\r[\t]{1,}[a-za-z0-9_]{1,} ([a-za-z0-9_]{1,}) = iterator\.next\(\);
replace:
for($1 $3 : $2) {
Comments
Post a Comment