aspose file tools*
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
Author

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,
Jan
Dirk Schreckmann
Sheriff

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]
 
Consider Paul's rocket mass heater.
 
subject: casting into primitive wrapper class