I have a variable like that:
List<Double> frameList = new ArrayList<Double>();
/* Double elements has added to frameList */
How can I have a new variable has a type of double[] from that variable in Java with high performance?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
High performance – every
Doubleobject wraps a singledoublevalue. If you want to store all these values into adouble[]array, then you have to iterate over the collection ofDoubleinstances. AO(1)mapping is not possible, this should be the fastest you can get:Thanks for the additional question in the comments 😉 Here’s the sourcecode of the fitting
ArrayUtils#toPrimitivemethod:(And trust me, I didn’t use it for my first answer – even though it looks … pretty similiar 😀 )
By the way, the complexity of Marcelos answer is O(2n), because it iterates twice (behind the scenes): first to make a
Double[]from the list, then to unwrap thedoublevalues.