Wednesday, October 12, 2005, 11:39:25 AM, you wrote:
> Oto Buchta wrote:
>>String[] pole = list.toArray(new String[list.size()]);
>>
> Ja bych pouze rad podotknul, ze alokace pole s velikosti list.size() je
> zbytecna; vracene pole je alokovano uvnitr metody
> List.toArray(Object[]) a parametr je pouzit pouze pro identifikaci jeho
> typu. Takze je dle meho nazoru lepsi setrit pamet a pouzit
nie celkom pravda...
* Returns an array containing all of the elements in this collection;
* the runtime type of the returned array is that of the specified array.
* If the collection fits in the specified array, it is returned therein.
* Otherwise, a new array is allocated with the runtime type of the
* specified array and the size of this collection.<p>
teda pole sa vytvara znovu len ak je to potrebne...
> String[] pole = list.toArray(new String[0]);
a toto je plytvanie, pretoze
- vytvorim objekt ktory potom zahodim
- implementacia AbstractCollection.toArray() vytvori nove pole pomocou
reflection...
navyse to trochu degraduje citatelnost kodu, pretoze je to nelogicky
zapis...
proste
list.toArray(new String[list.size()])
ma svoj zmysel...
--
Patrik Beno
J2EE Software Architect
____________________________________
Cleverlance - The Clever Enterprise Solutions
www.cleverlance.com
European Business Center
Dukelskych hrdinu 34
170 00 Praha 7
Czech Republic
Tel.: +420 266 177 166
Mobile: +420 777 929 450
Fax: +420 266 177 155