Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long[] to long[] and vice versa?

Tags:

java

Does anybody know an efficient, quick and clean way to convert Long[] to long[] and vice versa in Java outside the obvious for-loop with (un)box&copy?

Note: This is not about unboxing Long or boxing long. I am explicitly talking about arrays!

"There is no better way than loop and copy" would also be an answer ;)

EDIT: I am aware of the implications of doing the above and that it is better to avoid it. Just assume, I cannot avoid it and want to do it as smartly as possible without using 3rd party stuff.

like image 317
Fildor Avatar asked Nov 28 '22 08:11

Fildor


1 Answers

If you use apache commons lang you can do:

long[] primitive = ArrayUtils.toPrimitive(new Long[]{1L, 2L, 3L, 4L});
like image 109
José Roberto Araújo Júnior Avatar answered Dec 16 '22 03:12

José Roberto Araújo Júnior