-1

Bundle object doesn't let me pass a Double[] array because it require a double[] array. i'm not able to cast double[] to Double[] and I don't know what to do.

Help me please.

bazingaa
  • 38
  • 4
  • 2
    Please post an [SSCCE](http://sscce.org/) to help clarify the issue that you are having. – Chris Sprague Dec 12 '14 at 17:46
  • why you dont do to create a Double[] manually, and copy from double[] – Adem Dec 12 '14 at 17:46
  • According to [this very similar question](http://stackoverflow.com/questions/1109988/how-do-i-convert-double-to-double), the only option appears to be looping through and unboxing (or boxing in your case) the array - by a third party library or your own code. – snickers10m Dec 12 '14 at 17:47
  • try to serialize, then add to a getSharedPreferences, and read in the other activity... and unserialize it – BredeBS Dec 12 '14 at 17:49

1 Answers1

0

You could loop through the Double array and populate the double array by assigning to every value the output of Double.doubleValue(); Once that is done you can put your double[] array in the Bundle

Double D[];
double d[];
for(int i=0 ; i<D.length ; ++i) {
    d[i] = D[i];
}

Of course I did not initialize the variables but it's merely to give an example

Update
For anyone reading this I have also found this similar question that can be useful. It is abount using a 3rd party library to solve this problem and some comments add some nice information abount performance in different scenarions. Check it out: How do I convert Double[] to double[]?

Community
  • 1
  • 1
Francesco D.M.
  • 2,129
  • 20
  • 27
  • There is not need to do this. `Double` is **[autoboxed and unboxed](https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html)**. Though it is an object, it can be used as a value. –  Dec 12 '14 at 18:00
  • @scheisse_minelli then please explain how one could put a Double[] in a Bundle using Unboxing – Francesco D.M. Dec 12 '14 at 18:05
  • Oh sheesh, I guess I didn't read the question clearly enough. You're right. –  Dec 12 '14 at 18:17
  • @scheisse_minelli not a problem...but could my code be improved using unboxing instead of Double.doubleValue(); ? Would that work better? – Francesco D.M. Dec 12 '14 at 18:20
  • Oh yeah, you could just say `d[i] = D[i]`. –  Dec 12 '14 at 18:46
  • @scheisse_minelli good, thank you, I edited my answer with this information – Francesco D.M. Dec 12 '14 at 18:56
  • i get it, but i was looking for a better way. anyway it works, so.. that's ok – bazingaa Dec 13 '14 at 09:07