Forums Register Login

Behavior of Arrays.asList()

+Pie Number of slices to send: Send
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 ?!
+Pie Number of slices to send: Send
Because an array is just a single object, or have I misunderstood you?
+Pie Number of slices to send: Send
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.

+Pie Number of slices to send: Send
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 ?
+Pie Number of slices to send: Send
 

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 ]
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1146 times.
Similar Threads
How to use enhanced loop
Convert list to array
why the list size is 1
why can not print List's content?
generics 1.4
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:50:16.