Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Behavior of Arrays.asList()

 
Olivier Ledru
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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 ?!
 
Taariq San
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because an array is just a single object, or have I misunderstood you?
 
ramesh maredu
Ranch Hand
Posts: 210
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic