I\'m implementing an interface that has functionality similar to a table that can contain an types of objects. The interface specifies the following function:
Unfortunately you will need to loop through the entire list and unbox the Double
if you want to convert it to a double[]
.
As far as performance goes, there is some time associated with boxing and unboxing primitives in Java. If the set is small enough, you won't see any performance issues.
If you wanted to return a double[]
, you would need to create a new double[]
, populate it, and return that.
That may be a good architecture decision. First, it doesn't make a lot of sense to cast an Object[]
to a Double[]
; it's not really an array of Double
because there could be Object
s in it too. Second, if you return the array directly, the user code can modify it and alter the internal structure of your object.
The main performance impact would be in returning an array of double[]
, due to unboxing and the cost of allocation.