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.
Advertisement
Answer
There is no better way than loop and copy
The best solution is to avoid converting in the first place. If you are worries about efficiency avoid using Long[]
as it is many times larger than long[]
If you need to use a collection you can try TLongArrayList which wraps a long[].