This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman 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 Building Microservices this week in the Design 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
 
Have you checked out Aspose?
 
subject: Can vectors only hold objects?
 
It's not a secret anymore!