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[]?
--
To reply to me directly, please remove "_NoSpam_" from my email address
|
|
0
|
|
|
|
Reply
|
dl-notspam-rubin (1)
|
8/16/2003 6:20:53 PM |
|
On Sat, 16 Aug 2003 11:20:53 -0700, Daniel wrote:
> 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: spamfang@kimmeringer.de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
Always remember: The answer is forty-two, there can only be wrong
questions!
|
|
0
|
|
|
|
Reply
|
news2003081 (8)
|
8/16/2003 6:42:25 PM
|
|
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 Kimmeringer wrote:
> On Sat, 16 Aug 2003 11:20:53 -0700, Daniel wrote:
>
> > 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: spamfang@kimmeringer.de
> PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
>
> Always remember: The answer is forty-two, there can only be wrong
> questions!
--
To reply to me directly, please remove "_NoSpam_" from my email address
|
|
0
|
|
|
|
Reply
|
dl-notspam-rubin (1)
|
8/16/2003 8:47:17 PM
|
|
On Sat, 16 Aug 2003 13:47:17 -0700, Daniel wrote:
> 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: spamfang@kimmeringer.de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
Always remember: The answer is forty-two, there can only be wrong
questions!
|
|
0
|
|
|
|
Reply
|
news2003081 (8)
|
8/16/2003 8:56:17 PM
|
|
On Sat, 16 Aug 2003 11:20:53 -0700, Daniel
<dl-notspam-rubin@yahoo.com> wrote or quoted :
>Can I convert a vector to double[], or is there a quick conversion from
>Double[] to double[]?
see http://mindprod.com/converter.html for how to interconvert Double
and double (or anything else).
Then put it in a loop. Allocate a new array of the correct type and
size before you start.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
|
0
|
|
|
|
Reply
|
roedy (1019)
|
8/16/2003 9:34:44 PM
|
|
|
4 Replies
31 Views
(page loaded in 0.066 seconds)
|