• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Behavior of Arrays.asList()

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Just wonder why Arrays.asList() has this behavior when passing an int[] !?
Why asList take it as a single Object, and not as a regular array ?!
 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because an array is just a single object, or have I misunderstood you?
 
Ranch Hand
Posts: 210
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the primitive array int[] arrayInt = new int[] {1,2,3,4}, i think here it is considered as single array object.
But in case of wrapper array each elements are cosidered as objects,

I am also not sure about it, i came to conclusion based on retrun type of Arrays.asList method in both the cases generated by eclipse IDE.

 
Olivier Ledru
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, after reading http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#asList(T...) ,
Why int[] is not read as 'int...' but Integer[] is read as 'Integer...' ?
Nothing in the API point any difference on this.
Did I miss something ?
 
Taariq San
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Olivier Ledru:
Well, after reading http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#asList(T...) ,
Why int[] is not read as 'int...' but Integer[] is read as 'Integer...' ?
Nothing in the API point any difference on this.
Did I miss something ?




Those are 4 different ints each shoved into Integer objects, that's 4 different objects, whereas arrayInteger is a single object, an array of Integers. If it's not a primitive it's an Object, that goes for arrays too.
[ June 03, 2008: Message edited by: Taariq San ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic