marvado a écrit :
> seems to work,
> all suggestions are valid for me
> thank you !
>
> "Boudewijn Dijkstra" <> wrote in message
> news:41b2e4e1$0$44093$ i.nl...
>
>>"Jim Cheng" <> schreef in bericht
>>news:coucu9$rko$...
>>
>>>Pedro is asking fir a String (comma delimitted) including the name, desc,
>>>and age.
>>>So the following does not work.
>>>
>>>>---------------still not tested ---------------
>>>>String catlist;
>>>>
>>>>for (int j = 0; j < Cat.length; j++)
>>>>{
>>>> if(j!=0) catlist += ",";
>>>> catlist += Cat[j].cName;
>>>>}
>>>>
>>>>
>>>
>>>try:
>>>
>>>String catlist;
>>>
>>>for (int j = 0; j < Cat.length; j++)
>>>{
>>> if(j!=0) catlist += ",";
>>> catlist += Cat[j].cName +","+ Cat[j].cDesc +","+ cat[j].cAge;
>>>}
>>
>>StringBuffer buf = new StringBuffer(cat.length * 30);
>>
>>buf.append(cat[0].cName).append(',').append(cat[0].cDesc)
>> .append(',').append(cat[0].cAge);
>>for (int j = 1; j < cat.length; j++)
>>{
>> buf.append(',').append(cat[j].cName).append(',')
>> .append(cat[j].cDesc).append(',').append(cat[j].cAge);
>>}
>>
>>String catlist = buf.toString();
>>
>>
>
>
>
Hi !
It could also be beautiful to override Cat.toString, and use
Collection.toString()...
i.e.
for Cat
String toString()
{
return new
StringBuffer(cName).append(',').append(cDesc).appe nd(',').append(cAge)
}
then
// Produces [ cat1, desc1, age1, cat2, desc2, age2 ]
String result_l = Arrays.asList(arrayOfCatObjects).toString();
// Remove 1st and last character [ & ]
result_l = result_l.substring(1, result_l.length-1);
|