Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > converting Object[] to double[]?

Reply
Thread Tools

converting Object[] to double[]?

 
 
Daniel
Guest
Posts: n/a
 
      08-16-2003
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


 
Reply With Quote
 
 
 
 
Lothar Kimmeringer
Guest
Posts: n/a
 
      08-16-2003
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: http://www.velocityreviews.com/forums/(E-Mail Removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
Reply With Quote
 
 
 
 
Daniel
Guest
Posts: n/a
 
      08-16-2003
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: (E-Mail Removed)
> 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


 
Reply With Quote
 
Lothar Kimmeringer
Guest
Posts: n/a
 
      08-16-2003
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: (E-Mail Removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-16-2003
On Sat, 16 Aug 2003 11:20:53 -0700, Daniel
<(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Thunderbird and converting Pegasus mail 'Captain' Kirk DeHaan Firefox 4 12-17-2004 05:50 PM
Converting 'flat' gate level names to hierarchical names Paddy McCarthy VHDL 3 09-24-2004 05:34 PM
Converting a text input field into a decimal TheRemedy ASP .Net 1 09-07-2004 09:55 AM
converting Mozilla mails into Outlook Express mails Martin Geers Firefox 1 07-17-2004 01:11 AM
How to force Mozilla 1.6 in converting NS once more? Maria Firefox 1 04-10-2004 05:10 PM



Advertisments