Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java doesn't provide any API to directly cast int[] to Integer[] ?

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java doesn't provide any API to directly cast int[] to Integer[] ?

Thanks.
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.

you have to go around using collection classes.
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edward:

Why would you need to do that anyway, since autoboxing should take care of the individual elements?

John.
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See Apache ArrayUtils.
The method toObject(int[] array) work for you. Hope it helps.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.Thats cool.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic