converting Object[] to double[]?

D

Daniel

Using Java 1.4.2, I'm trying to convert a vector to a double[].
If I try this:
double[] foo = vector.toArray(new double[5]);
I get a compile error. But it compiles just fine if I use Double[]
Can I convert a vector to double[], or is there a quick conversion from
Double[] to double[]?
 
L

Lothar Kimmeringer

Using Java 1.4.2, I'm trying to convert a vector to a double[].
If I try this:
double[] foo = vector.toArray(new double[5]);
I get a compile error. But it compiles just fine if I use Double[]

double is a primitive type and Vector is using an Object[] for
keeping the values, so it's possible to get a double[] out of
an Object[].
Can I convert a vector to double[], or is there a quick conversion from
Double[] to double[]?

Why can't you use a Double[] instead of a double[]? The only
thing you have to change is a call of doubleValue() when working
with the values.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
D

Daniel

I can't use Double[] because I'm using a library that needs me to pass in a
double[]
so I'd need to convert it to double[] before passing it it. I was hoping java
provides a method to take Double[] --> double[] without my having to build a
loop to do it manually.


Lothar said:
Using Java 1.4.2, I'm trying to convert a vector to a double[].
If I try this:
double[] foo = vector.toArray(new double[5]);
I get a compile error. But it compiles just fine if I use Double[]

double is a primitive type and Vector is using an Object[] for
keeping the values, so it's possible to get a double[] out of
an Object[].
Can I convert a vector to double[], or is there a quick conversion from
Double[] to double[]?

Why can't you use a Double[] instead of a double[]? The only
thing you have to change is a call of doubleValue() when working
with the values.

Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
L

Lothar Kimmeringer

I can't use Double[] because I'm using a library that needs me to pass in a
double[]
so I'd need to convert it to double[] before passing it it. I was hoping java
provides a method to take Double[] --> double[] without my having to build a
loop to do it manually.

You can also implement your own Vector working with double:

void DoubleVector.add(double);
double DoubleVector.get(int i);
....

A vector isn't very complicated to be implemented or just
use the existing sources of the classic vectors and
change the signature/underlying array.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top