• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Array.asList question

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The contract of Arrays.asList() says that :

Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.)


But , running the following code :


will produce as output 2,3,4. If the array of primitives is changed with an Integer array, then the output is the expected 8,3,4.

Can somebody explain please ?
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi



The API shows "Arrays.asList(Object[])" so the argument could be an Object[] instead of int[]. I tried this code and worked fine as you wanted it to do. I could not understand "for(Integer t: array)", how could I get this to work.

Thanks
Chandu
 
Liviu Carausu
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Chandu,
Actually the code is for jdk 5.0 and there the API signature is

.

Anyway,thanks to you, now I've got the point, the parameter must be an array of Objects, so my array of primitives is interpreted as a simple object.

Regards,

Liviu
 
Chandra Sagi
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem....
reply
    Bookmark Topic Watch Topic
  • New Topic