Is there any difference between long array (long[] arr
) and Long array (Long[] arr
)?
Is the sorting complexity the same?
Sorting long[]
and Long[]
using Arrays.sort
will involve different sorting algorithms: long[] is sorted with a "dual-pivot quick sort" while Long[] is sorted with "tim sort" (a version of merge sort). They will have the same O(n log n)
asymptotic time complexity, but the constant multiplier may be different. Operations on primitives and arrays of primitives like long[]
are typically more efficient than operations on wrapper objects.
Long[]
is an array of objects, whereas long[]
is an array of primitives. Sorting complexity is the same for both, but by wrapping primitive into an object, you're introducing additional memory overhead.