aspose file tools*
The moose likes Beginning Java and the fly likes Object array to Primitive Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Object array to Primitive Array" Watch "Object array to Primitive Array" New topic
Author

Object array to Primitive Array

vidya Sreedharan
Greenhorn

Joined: Jun 27, 2007
Posts: 4
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

Joined: Aug 31, 2004
Posts: 11343

Welcome to JavaRanch!

Unless I'm mistaken, I think a loop is your only option.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14430
    
  23

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:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
vidya Sreedharan
Greenhorn

Joined: Jun 27, 2007
Posts: 4
Thanks everyone!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object array to Primitive Array