File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes which object can be add into a Vector? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "which object can be add into a Vector?" Watch "which object can be add into a Vector?" New topic
Author

which object can be add into a Vector?

Gong James
Ranch Hand

Joined: Oct 15, 2001
Posts: 77
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

Joined: Aug 26, 2001
Posts: 7610
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


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: which object can be add into a Vector?
 
Similar Threads
"Strings"
autoboxing in vectors
Vector initialization
Creating an instance of Vector Class and adding an Element?
DefaultTableModel and Vector