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.
java.util.List method-Object[] toArray(Object[] a)returns same array?
kathir je
Greenhorn
Joined: Jun 07, 2006
Posts: 12
posted
0
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
posted
0
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
posted
0
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.