Results 1 to 6 of 6

Thread: add/get double to vector

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    New Jersey
    Posts
    334

    add/get double to vector

    Hello,
    I'm having troubles using Vectors. Basically, I am being forced to use Vectors as a way of storing a list of doubles.

    i want to be able to do the following:

    Code:
    Vector myVector = new Vector();
    double mydouble = 0.5;
    myVector.add(mydouble);
    But apparently this won't work because Vectors store Object, and ?doubles are not objects?

    So I do this:
    Code:
    myVector.add(new Double(mydouble))
    But if I do this, how do I later retrieve the double's from the Vector?

    I want to say:
    Code:
    newdouble = myVector(0);//assuming that mydouble was stored at index 0
    But that doesn't work

    Please help!
    Alex

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: add/get double to vector

    If you are not able to use generics (version < 1.5), then you need to cast from an Object to a Double...
    Code:
    Double newdouble = (Double)myVector(0);//assuming that mydouble was stored at index 0
    That should work.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    New Jersey
    Posts
    334

    Re: add/get double to vector

    Thanks for that

    I think I will try to find some other type of data structure for this though, as Vectors seem to have quite a few drawbacks.

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: add/get double to vector

    Why don't you try the ArrayList?
    it's almost like the Vector but quite better in your case
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    New Jersey
    Posts
    334

    Re: add/get double to vector

    Yea that's what I came across as well, seems more suitable.

    Thanks
    Alex

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: add/get double to vector

    Quote Originally Posted by spandex44
    Yea that's what I came across as well, seems more suitable.

    Thanks
    Alex
    You're welcome anytime
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width