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

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -