Example usage for java.util Vector Vector

List of usage examples for java.util Vector Vector

Introduction

In this page you can find the example usage for java.util Vector Vector.

Prototype

public Vector(Collection<? extends E> c) 

Source Link

Document

Constructs a vector containing the elements of the specified collection, in the order they are returned by the collection's iterator.

Usage

From source file:Main.java

public static void main(String[] args) {

    Vector vec = new Vector(4);

    vec.add(4);/*from ww w .j ava 2s .  c o  m*/
    vec.add(3);
    vec.add(2);
    vec.add(1);

    // let us remove the 1st element
    System.out.println("Removed element: " + vec.remove(1));
}

From source file:Main.java

public static void main(String[] args) {

    Vector vec = new Vector(4);

    vec.add(4);// www. j  av  a2 s  .com
    vec.add(3);
    vec.add(2);
    vec.add(1);

    // let us get the 3rd element of the vector
    System.out.println("Third element is :" + vec.get(3));
}

From source file:MainClass.java

public static void main(String args[]) {
    Vector v = new Vector(5);
    for (int i = 0; i < 10; i++) {
        v.add(0, i);/*from   w  w w  .  j a  va 2  s .c o m*/
    }
    System.out.println(v);

    v.setSize(3);

    System.out.println(v);
}

From source file:Main.java

public static void main(String[] args) {

    Vector vec = new Vector(6);

    vec.add(6);/* ww w.java 2  s  .c  o  m*/
    vec.add(5);
    vec.add(4);
    vec.add(3);
    vec.add(2);
    vec.add(1);

    System.out.println("index is: " + vec.lastIndexOf(1, 4));
}

From source file:Main.java

public static void main(String[] args) {

    Vector vec = new Vector(4);

    vec.add(4);/*from  w  ww. j  a  va2  s . c o  m*/
    vec.add(3);
    vec.add(2);
    vec.add(1);

    // convert the contents into string
    System.out.println(vec.toString());

}

From source file:Main.java

public static void main(String[] args) {

    Vector vec = new Vector(6);

    vec.add(4);//  ww w . ja  v  a  2  s .c om
    vec.add(3);
    vec.add(2);
    vec.add(1);
    vec.add(2);
    vec.add(1);

    // let us print the last index of 1
    System.out.println("last index :" + vec.lastIndexOf(1));
}

From source file:Main.java

public static void main(String args[]) {
    Vector v = new Vector(5);
    for (int i = 0; i < 10; i++) {
        v.add(0, i);//w  ww. j a va2 s .  com
    }
    System.out.println(v.capacity());
    System.out.println(v);

    v.remove(1);

    v.removeElementAt(2);

    System.out.println(v);
    System.out.println(v.capacity());

}

From source file:Main.java

public static void main(String args[]) {
    Vector v = new Vector(5);
    for (int i = 0; i < 10; i++) {
        v.add(0, i);/*from  w ww  .j  a  va  2 s . c  om*/
    }
    System.out.println(v.capacity());
    System.out.println(v);

    v.remove(new Integer(9));

    v.removeElement(new Integer(2));

    System.out.println(v);
    System.out.println(v.capacity());

}

From source file:MainClass.java

public static void main(String args[]) {
    Vector v = new Vector(5);
    for (int i = 0; i < 10; i++) {
        v.add(i, 0);// w  ww .  ja v a2  s  . c  o  m
    }
    System.out.println(v.capacity());
    System.out.println(v);

    v.clear();

    System.out.println(v);
    System.out.println(v.capacity());

}

From source file:Main.java

public static void main(String args[]) {
    Vector vec = new Vector(5);
    for (int i = 0; i < 10; i++) {
        vec.add(0, i);/*from   w  ww .  ja va 2 s .c  o m*/
    }
    System.out.println("Content of the vector: " + vec);
    System.out.println("Size of the vector: " + vec.size());

    // ensure the capacity of the vector and add elements
    vec.ensureCapacity(40);
    for (int i = 0; i < 10; i++) {
        vec.add(0, i);
    }
    System.out.println(vec);
    System.out.println(vec.size());
}