• 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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....
 
Hot dog! An advertiser loves us THIS much:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!