• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 76453
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Can you hear that? That's my theme music. I don't know where it comes from. Check under this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic