How to convert long array to Long array , long [] to Long[]

Today i facing one funny problem, i need to convert a primitive long array (long[]) to an object Long[]. First I thought java JDK should provided this kind of function, however i failed to find it. I have to use a for loop to convert it manually. Below is the covertion source code.


long [] largument = (long[])argument;
Long Largument [] = new Long[largument.length];
int i=0;
					
for(long temp:largument){
    Largument[i++] = temp;
}

This solution is apply to other primitive array to object array as well, hope help.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
2 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
3 Comment authors
wowAnonymoussanjers Recent comment authors
newest oldest most voted
sanjers
Guest
sanjers

We can use org.apache.commons.lang.ArrayUtils.toObject to convert long[] to Long[].

Anonymous
Guest
Anonymous

Arrays.asList(longArray).toArray(new Long[longArray.size()]);