File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 24199

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
It's not a secret anymore!