|
-
Feb 1st, 2006, 02:31 PM
#1
Thread Starter
Hyperactive Member
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
-
Feb 1st, 2006, 05:29 PM
#2
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
-
Feb 2nd, 2006, 10:15 AM
#3
Thread Starter
Hyperactive Member
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.
-
Feb 2nd, 2006, 01:36 PM
#4
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
-
Feb 2nd, 2006, 03:15 PM
#5
Thread Starter
Hyperactive Member
Re: add/get double to vector
Yea that's what I came across as well, seems more suitable.
Thanks
Alex
-
Feb 2nd, 2006, 04:59 PM
#6
Re: add/get double to vector
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|