Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can vectors only hold objects?

 
Willie Toma
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it true that Vectors can only hold objects?
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic