• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

how do I use vector

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have searched around a bit and I couldn't find any help one it. The text book is no help.
WL.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is what I know. Use ArrayList instead of Vector unless you want to use only java 1(like in an applet).
 
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
W Lam
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
W Lam
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic