Can I iterate over an array defined within a for-loop in Java? -


does java offer way following without resorting declaring array in separate variable?

for (string s : {"hey", "there"}) {     // ... } 

the best can come is:

for (string s : new arraylist<string>() {{ add("hey"); add("there"); }}) {     // ... } 

which isn't pretty.

well, least can this:

for (string s : new string[]{"hey", "there"}) {     // ... } 

since arrays "iterable" in java (although not implementing iterable), iterate on array instead of arraylist, in-line initialized.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -