This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Can vectors only hold objects? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can vectors only hold objects?" Watch "Can vectors only hold objects?" New topic
Author

Can vectors only hold objects?

Willie Toma
Ranch Hand

Joined: May 11, 2001
Posts: 78
Is it true that Vectors can only hold objects?
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

True
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695



If you want it to hold 'primitive' types, like integers, floats, doubles, etc...

You can wrap these values in their respective Object types and store those in the Vector. Getting them out again is a bit trickier.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Which means that if you want to put a primitive in one, then you need to put it in a wrapper object. So you would put a double in a Double object etc. In which case, vectors can hold anything (sort of).


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
 
subject: Can vectors only hold objects?
 
Similar Threads
Array vs Vector
Vector Question!!
Difference b/w Array, arraylist, vector
Vector Question
problem in vector