• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which object can be add into a Vector?

 
Gong James
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confused by the following code of a scjp.
original code:
which of the following will successfully create an instance of Vectort class and add an element?
a) Vector v=new Vector(99);
v[1]=99;
b) Vector v=new Vector();
v.addElement(99);
c) Vector v=new Vector();
v.add(99);
d) Vector v=new Vector();
v.addElement("99");
The given ans: d
does that means only only a String can be add into a Vector?I dont knwo which of the following can be add into a instance of a vector on earth,a byte or int or char or String?
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
only objects may be added to a Vector instance, i.e. String, primitive wrappers, or whatever but no primitive type !!!
HIH

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic