How do I convert Double[] to double[]?

后端 未结 8 1727
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 09:04

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:



        
相关标签:
8条回答
  • 2020-11-28 09:42

    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.

    0 讨论(0)
  • 2020-11-28 09:43

    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 Objects 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.

    0 讨论(0)
提交回复
热议问题