Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

casting into primitive wrapper class

 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic