Re: confused
- From: Roedy Green <my_email_is_posted_on_my_website@xxxxxxxxxxxxxx>
- Date: Mon, 31 Oct 2005 04:24:52 GMT
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.
.
- Prev by Date: Re: Crazy Clock
- Next by Date: Re: java virtual machine error -- FIXED
- Previous by thread: Re: confused
- Next by thread: Re: How to hide information from address line of JSP?
- Index(es):