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©?
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.
If you use apache commons lang you can do:
long[] primitive = ArrayUtils.toPrimitive(new Long[]{1L, 2L, 3L, 4L});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With