This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes java.util.List method-Object[] toArray(Object[] a)returns same array? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "java.util.List method-Object[] toArray(Object[] a)returns same array? " Watch "java.util.List method-Object[] toArray(Object[] a)returns same array? " New topic
Author

java.util.List method-Object[] toArray(Object[] a)returns same array?

kathir je
Greenhorn

Joined: Jun 07, 2006
Posts: 12
Hi All,

I like to know when to use the following java.util.List method

Object[] toArray(Object[] a)

I was very much confused. The return type is object array and the parameter is object array. then what is the difference. can anyone explain this in detail.

for example if i pass a string array i am going to get the same string array as return then what is the use???

Thanks,
J.Kathir
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
Welcome to the Ranch.

Are you still using J1.4? You would do better to update to J2SE5.0, which largely dispenses with Objects in Collections and Lists.

Please have a look at the toArray() method in the java.util.List interface. Read very carefully what it takes as parameters. And what its return type is.
The parameter is not the source of the information at all.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3011
    
    9
Originally posted by kathir je:

for example if i pass a string array i am going to get the same string array as return then what is the use???


You pass an empty string array - you get back an array (not necessarily the same one) populated with all the strings from the List. That sounds quite useful to me.


Joanne
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: java.util.List method-Object[] toArray(Object[] a)returns same array?
 
Similar Threads
Collections
Setting the size of an array
Generics Question
How is priority determined?-Collection Doubt
dragdrop-colections