What do you want to do with a vector? Here are some basics: import java.util.Vector;
int number = new int(34); Double number2 = new Double (15.95); Vector myVector = new Vector(); myVector.addElement ("Add"); myVector.addElement ("Whatever"); myVector.addElement (number); myVector.addElement (number2); There's also .removeElement(Object element) .contains(Object element) .elementAt(int Index) .firstElement() .lastElement() .size() Also, you can do something like myVector.insertElementAt("Name", 0); myVector.removeAllElements(); Hope this helps! [This message has been edited by Kathy Lynch (edited March 09, 2001).]
Randall I used to use that same rule for choosing which Collection I would use but I have since learned that you should use a Vector when you need synchronization and ArrayList if you do not. Vectors are slower because they are internally synchronized whereas ArrayLists are a tad speedier (for accessing) because the are not synchronized. Hope this helps.
I am programing an application file. which involves reading data in and writing it out. I need to learn how to use Vector to store the data and use it for caculation. The structure is divided in to two files. One named "grades" which only defines the variables and functions. The other file contains the main function. Please help. wl [This message has been edited by W Lam (edited March 10, 2001).]
oh, some detailed questions would be: How do I know what's being added into my vector? I have defined some of the variables as follow: private String name; private int grade; private double average; The problem in here is how do I define a Vector that contains these 3 variables. Then the question would be How do I call the elements in a vector? like how would I add the grades up like: myVector.addElement = student1grade + student1grade
Hey W Lam, A vector, unlike an array, can contain objects of different classes. So, do not worry about defining a vector to add ojects of diff classes. myVector.addElement() adds object to the vector and not for adding up numbers. hope this helps. regards, eagerbeaver.
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
Gift giving made easy with the permaculture playing cards