2

I have a function in a jar file which accepts two parameters:

  1. An Object array which mentions the type and number of output
  2. An Object array which contains input to the function.

The input I need to pass consists of 7 objects. I have to send two double[] arrays and rest all 5 are double values.

I would like to know how to convert double[] into an Object.

Please help me with this.

If i want to convert a single double value to an object of Double, I can use the following code.

public class JavadoubleToDoubleExample {

  public static void main(String[] args) {
    double d = 10.56;

    /*
    Use Double constructor to convert double primitive type to a Double object.
    */ 

    Double dObj = new Double(d);
    System.out.println(dObj);

  }
}

Output:

10.56

But what if the d={1.0,8.9,4.0,7.9}.

How can I convert the array into an object of Double?

Azeem
  • 11,148
  • 4
  • 27
  • 40

1 Answers1

0

Arrays are already Objects in Java. If you want to convert an array of primitive double into an array of Objects:

double[] nums = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7};        
Object[] objs = new Object[nums.length];

for(int i=0; i<nums.length; i++)
    objs[i] = new Double(nums[i]);
user3437460
  • 17,253
  • 15
  • 58
  • 106