• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
kathir je
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 56220
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!