Can this use of Java 1.5 for be make more terse?
public class ForTest
{
/**
* test harness
*
* @param args not used
*/
public static void main ( String[] args )
{
for ( String s : new String[] { "pony", "horse", "mare"} )
{
System.out.println( s );
} // end for
} // end main
} // end ForTest

Signature
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
Dale King - 29 Jun 2005 08:27 GMT
> Can this use of Java 1.5 for be make more terse?
>
[quoted text clipped - 13 lines]
> } // end main
> } // end ForTest
Depends on your definition of terseness, but refactoring that code into
a method will let you get rid of the array initializer syntax. You can
be the judge if that is an improvement in your situation:
public class ForTest
{
public static void print( String... strings )
{
for( String s : strings )
{
System.out.println( s );
}
}
public static void main( String[] args )
{
print( "pony", "horse", "mare" );
}
}

Signature
Dale King
Wibble - 30 Jun 2005 01:20 GMT
> Can this use of Java 1.5 for be make more terse?
>
[quoted text clipped - 13 lines]
> } // end main
> } // end ForTest
terse:
public class ForTest { public static void main(String[] a) {
System.out.println("pony,horse,mare"); } }
Roedy Green - 30 Jun 2005 07:32 GMT
>> public class ForTest
>> {
[quoted text clipped - 16 lines]
>public class ForTest { public static void main(String[] a) {
>System.out.println("pony,horse,mare"); } }
It does not produce the same result. You left out the \ns .
What I was up to was code for iterating over an ad hoc collection of
enums, or strings.
In PL/I you could say something vaguely similar to :
for ( String s = "pony", "horse","mare" )
I was hoping there was something in the new 1.5 syntax similar.

Signature
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes