converting Object[] to double[]?

Discussion in 'Java' started by Daniel, Aug 16, 2003.

  1. Daniel

    Daniel Guest

    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
    Daniel, Aug 16, 2003
    #1
    1. Advertising

  2. 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:
    PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

    Always remember: The answer is forty-two, there can only be wrong
    questions!
    Lothar Kimmeringer, Aug 16, 2003
    #2
    1. Advertising

  3. Daniel

    Daniel Guest

    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:
    > 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
    Daniel, Aug 16, 2003
    #3
  4. 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:
    PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

    Always remember: The answer is forty-two, there can only be wrong
    questions!
    Lothar Kimmeringer, Aug 16, 2003
    #4
  5. Daniel

    Roedy Green Guest

    On Sat, 16 Aug 2003 11:20:53 -0700, Daniel
    <> 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.
    Roedy Green, Aug 16, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Web learner

    from List <double> to double[]

    Web learner, Apr 25, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    474
  2. sb
    Replies:
    4
    Views:
    302
    Alberto Barbati
    Feb 19, 2004
  3. Jacek Dziedzic
    Replies:
    5
    Views:
    384
    Old Wolf
    Apr 8, 2004
  4. Sydex
    Replies:
    12
    Views:
    6,483
    Victor Bazarov
    Feb 17, 2005
  5. Joe Van Dyk
    Replies:
    3
    Views:
    284
    Joe Van Dyk
    Aug 11, 2006
Loading...

Share This Page