Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Forums
Register
Login
Java
»
Beginning Java
Java doesn't provide any API to directly cast int[] to Integer[] ?
Edward Chen
,
Ranch Hand
Oct 29, 2009 10:57:01
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
Java
doesn't provide any API to directly cast int[] to Integer[] ?
Thanks.
Siva Masilamani
,
Ranch Hand
Oct 29, 2009 11:13:12
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
No.
you have to go around using collection classes.
John de Michele
,
Rancher
Oct 29, 2009 11:34:25
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
Edward:
Why would you need to do that anyway, since autoboxing should take care of the individual elements?
John.
Muhammad Khojaye
,
Ranch Hand
Oct 29, 2009 11:49:48
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
See Apache
ArrayUtils
.
The method toObject(int[] array) work for you. Hope it helps.
Rob Spoor
,
Sheriff
staff
Oct 29, 2009 14:12:11
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
Siva Masilamani wrote:
you have to go around using collection classes.
Not really; the following code will do exactly the same as the ArrayUtils method Muhammed mentioned, and is not using collection classes:
// int[] array Integer[] array2 = new Integer[array.length]; for (int i = 0; i < array.length; i++) { array2[i] = array[i]; // auto boxing }
Siva Masilamani
,
Ranch Hand
Oct 29, 2009 14:30:15
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
Yes.Thats cool.
Post by:
autobot
This is my favorite tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
This thread has been viewed 1154 times.
Similar Threads
Question about int... and Integer from Java Inquisition
Variable Madness
Putting digits one by one
Converting int to String
Widening & Boxing
More...
All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:14:32
.