Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Object array to Primitive Array  RSS feed

 
vidya Sreedharan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is there a better way of copying elements from a Long arrray to a primitive long array rather than assigning each element in a for loop.

Thanks,
Vidya
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

Unless I'm mistaken, I think a loop is your only option.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I concur.

Even if there is a method, behind the scened, it's probably just doing a loop as well. Write your own loop, and make it as efficient as you can.

Good luck!

-Cameron McKenzie
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15861
81
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no convenient way to do this with a Java language construct, nor is there a convenient method in the standard Java API to do this. So you will have to write a loop.

However, the Apache Jakarta Commons Lang utility library (open source) contains a class ArrayUtils which makes it easy:
 
vidya Sreedharan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone!!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!