This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes toArray() question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "toArray() question" Watch "toArray() question" New topic
Author

toArray() question

Charith Fernando
Ranch Hand

Joined: Sep 12, 2005
Posts: 67
hi,

i have seen code segments which uses the toArray() in different ways... just want to know the best mechanism and the difference...

(1)



(2)




please note that this is in Java 1.4 in Java 5 we dont need the cast if we have a list which will only contain Strings...


Thank you
Charith


Charith I Fernando<br />SCJP5, SCWCD, SCBCD, BSc(Hons) IS<br />+94 773 263 222 (mobile)
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023

If the passed array is large enough to contain the values to be returned, the method returns the passed array reference (that now contains the values to be returned) and not a newly created one.
[ October 23, 2006: Message edited by: wise owen ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: toArray() question
 
Similar Threads
Using Lists and converting them to arrays problem
Doubt in toArray() method
dragdrop-colections
Collection toArray( T[ ] ) method
toArray(new String[0])