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 Beginning Java and the fly likes Collections - toArray Method 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 » Java » Beginning Java
Bookmark "Collections - toArray Method" Watch "Collections - toArray Method" New topic

Collections - toArray Method

Landon Blake
Ranch Hand

Joined: Dec 04, 2003
Posts: 121
The Collection Documentation States:
"The toArray methods are provided as a bridge between collections and older APIs that expect arrays on input. They allow the contents of a Collection to be translated into an array. The simple form with no arguments creates a new array of Object. The more complex form allows the caller to provide an array or to choose the runtime type of the output array."
When toArray is called, and the collection is "translated" to the array, do the objects still exist in the LinkedList.
Can I call toArray on the same LinkedList multiple times to create arrays with different names but containg the same set of objects?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24166

Calling toArray() doesn't change a collection in any way, so the answer to both your questions is "yes".

[Jess in Action][AskingGoodQuestions]
Landon Blake
Ranch Hand

Joined: Dec 04, 2003
Posts: 121
Thanks Ernest...That's what I suspected.
[ May 06, 2004: Message edited by: Landon Blake ]
I agree. Here's the link:
subject: Collections - toArray Method
Similar Threads
Return List or Object[]
How to convert set to char[]?
An object to hold several arrays
struts 1.2.7: html:multibox and no checked checkboxes - how does "matches" work?
HashMap Buckets