• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Array.asList question

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
No problem....
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!