Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Java Vector int

Hi All,

I have a int variable which I would like to add to Vector object. Any example on how to add int to Vector object?

Thanks in advance.
No votes yet
Share this
1 answer
hertze_bogdan's picture
The Vector class implements a growable array of objects. An int is a simple data type and it does nor inherits from Object. So this is why you can't add the int variable to the Vector object. You should use Integer, like this:
  1. Vector vector = new Vector();
  2. vector.addElement(new Integer(5));
No votes yet