Add elements to this vector

boolean add(E e)
Appends the specified element to the end of this Vector.
void add(int index, E element)
Inserts the specified element at the specified position in this Vector.
boolean addAll(Collection<? extends E> c)
Appends all of the elements in the specified Collection to the end of this Vector, in the order that they are returned by the specified Collection's Iterator.
boolean addAll(int index, Collection<? extends E> c)
Inserts all of the elements in the specified Collection into this Vector at the specified position.
void addElement(E obj)
Adds the specified component to the end of this vector, increasing its size by one.
void insertElementAt(E obj, int index)
Inserts the specified object as a component in this vector at the specified index.

  import java.util.Vector;

public class Main{

  public static void main(String args[]) {

    Vector v = new Vector();

    for(int i = 0; i < 5; i++) {
      v.addElement("java2s.com "+i);
    }

    for(int i = v.size() - 1; i >= 0; i--) {
      System.out.print(v.elementAt(i) + " ");
    }
  }
}
  

The output:


java2s.com 4 java2s.com 3 java2s.com 2 java2s.com 1 java2s.com 0
Home 
  Java Book 
    Collection  

Vector:
  1. Vector class
  2. Create Vector objects
  3. Add elements to this vector
  4. Size and capacity
  5. Remove all elements from a vector
  6. Clone a vector
  7. Does it contain a certain element
  8. Copy elements in vector to an array
  9. Get Enumeration from this vector
  10. Compare two vectors
  11. Get element from vector
  12. Is vector empty
  13. Get element index
  14. Remove element from a vector
  15. Retain elements collection c has
  16. Replace element in a vector
  17. Get a sub list from a list
  18. Convert Vector to Array