Search code examples
javaandroidandroid-intentbundle

How can i pass a Double[] array to another activity


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.


Solution

  • 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[]?