Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Collections - toArray Method" Watch "Collections - toArray Method" New topic
Author

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?
Thanks,
Landon
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.
Landon
[ May 06, 2004: Message edited by: Landon Blake ]
 
jQuery in Action, 2nd edition
 
subject: Collections - toArray Method
 
Similar Threads
An object to hold several arrays
How to convert set to char[]?
HashMap Buckets
struts 1.2.7: html:multibox and no checked checkboxes - how does "matches" work?
Return List or Object[]