Re: confused



On Sat, 29 Oct 2005 03:09:00 GMT, Real Gagnon
<realgagnon_@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote, quoted or
indirectly quoted someone who said :

> public String toString()
> {
> String _scores = "";
> for (Object score : scores.toArray())
> {
> _scores += (Integer)score + " ";
> }
> return _scores;
> }

Presuming that scores is an ArrayList<String>
I would write that as :

public String toString()
{
StringBuilder sb = new StringBuilder( 50 /* ?? */ );
sb. append( "[ " );
for (String score : scores )
{
sb.append( score );
sb.append( ' ' );
}
sb.append( ']' );
return sb.toString();
}



--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
.