File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes casting into primitive wrapper class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "casting into primitive wrapper class" Watch "casting into primitive wrapper class" New topic

casting into primitive wrapper class

Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
hi there,
playing with the Collection Framework, I was wondering about the following issue:
What is the most efficient way (or: _any_ way but a loop) to cast a array of primitives
int myArray[] = {1,2,3,4,5}
into a array of Integer wrapper objects?
My goal was to be able to handle myArray[] as a Collection.
Arrays.asList(Object[] a)
looked like a appropriate method to me. But, as already quoted, I had to cast it manually to a help-array
Integer myHelpArray[]
which worked out, but doesn't look too efficient to me ;-)
thanks for any help,
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch, Jan!
We beginners aren't too interested in alleged efficiencies, especially as premature optimization is the root of all evil [Knuth]. We're more concerned with clarity of code.
Moving this to the Performance forum...
[ February 03, 2004: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: casting into primitive wrapper class
It's not a secret anymore!