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<Integer> vec = new Vector<Integer>(4);
    Vector<Integer> vecclone = new Vector<Integer>(4);

    vec.add(4);//w  w  w .  ja v  a2s.  c  o m
    vec.add(3);
    vec.add(2);
    vec.add(1);

    System.out.println(vec);

    // let us clone the vector vec
    vecclone = (Vector) vec.clone();

    System.out.println(vecclone);

}

From source file:Main.java

public static void main(String[] args) {

    Vector<Integer> vec = new Vector<Integer>(4);

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

    // let us print the size of the vector
    System.out.println("Size of the vector after addition :" + vec.size());
    System.out.println(vec);

    // let us clear the vector
    vec.clear();

    // let us print the size of the vector
    System.out.println("Size of the vector after clearing :" + vec.size());
}

From source file:Main.java

public static void main(String[] args) {
    Vector<Integer> firstvec = new Vector<Integer>(4);
    Vector<Integer> secondvec = new Vector<Integer>(4);

    // additing in firstvec
    firstvec.add(4);//from   ww w .j a  va  2s .c  om
    firstvec.add(3);
    firstvec.add(2);

    // additing in secondvec
    secondvec.add(4);
    secondvec.add(3);
    secondvec.add(2);

    // let us print all the elements available in vector
    System.out.println("Testing equality of firstvec and secondvec :" + firstvec.equals(secondvec));

}

From source file:Main.java

public static void main(String[] args) {

    Vector<Integer> vec = new Vector<Integer>(4);

    vec.add(0, 4);/*w w w.  j a  v a 2s  . co  m*/
    vec.add(1, 3);
    vec.add(2, 2);
    vec.add(3, 1);

    for (Integer number : vec) {
        System.out.println("Index :" + vec.indexOf(number) + " Number: " + number);
    }

    // added new number 10 at 3rd position/index
    vec.add(3, 10);

    for (Integer number : vec) {
        System.out.println("Index :" + vec.indexOf(number) + " Number: " + number);
    }
}

From source file:Main.java

public static void main(String[] args) {
    Vector<Integer> vec = new Vector<Integer>(4);
    Vector<Integer> vecretain = new Vector<Integer>(4);

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

    // this elements will be retained
    vecretain.add(5);
    vecretain.add(3);
    vecretain.add(2);

    vec.retainAll(vecretain);

    for (Integer number : vec) {
        System.out.println("Number = " + number);
    }
}

From source file:Main.java

public static void main(String[] args) {
    Vector<Integer> vec = new Vector<Integer>(4);
    Vector<Integer> vectest = new Vector<Integer>(4);
    Vector<Integer> vecdiff = new Vector<Integer>(4);

    vec.add(4);/*from   w w w. jav a 2 s  . c  o  m*/
    vec.add(3);
    vec.add(2);

    vectest.add(4);
    vectest.add(3);
    vectest.add(2);

    vecdiff.add(4);
    vecdiff.add(3);
    vecdiff.add(12);

    // let us check vec and vectest
    System.out.println(vectest.containsAll(vec));

    // let us check vec and vecdiff
    System.out.println(vecdiff.containsAll(vec));
}

From source file:Main.java

public static void main(String[] args) {
    Vector<Integer> firstvec = new Vector<Integer>(4);
    Vector<Integer> secondvec = new Vector<Integer>(4);

    // use add() method to add elements in the secondvec vector
    secondvec.add(5);//from   w ww  .j  a v a  2  s.  c  o  m
    secondvec.add(6);
    secondvec.add(7);
    secondvec.add(8);

    // use add() method to add elements in the firstvec vector
    firstvec.add(1);
    firstvec.add(2);
    firstvec.add(3);
    firstvec.add(4);

    /** use addAll() method to add elements of the 2nd vector at 
    1st element position of the first vector */

    firstvec.addAll(1, secondvec);

    System.out.println(firstvec);

}

From source file:Main.java

public static void main(String[] args) {
    Vector<Integer> vec = new Vector<Integer>(4);
    Integer[] anArray = new Integer[4];

    vec.add(4);//from w  w w. j av  a2 s.  c  om
    vec.add(3);
    vec.add(2);
    vec.add(1);

    // fill the array from the vector
    vec.toArray(anArray);

    for (int i = 0; i < anArray.length; i++) {
        System.out.println(anArray[i]);
    }
}

From source file:Main.java

public static void main(String[] args) {

    Vector<Integer> vec = new Vector<Integer>(4);

    Integer anArray[] = new Integer[4];

    anArray[0] = 100;/*w w w  .jav a 2s.  c  om*/
    anArray[1] = 100;
    anArray[2] = 100;
    anArray[3] = 100;

    vec.add(4);
    vec.add(3);
    vec.add(2);
    vec.add(1);

    for (Integer number : anArray) {
        System.out.println("Number = " + number);
    }

    // copy into the array
    vec.copyInto(anArray);

    for (Integer number : anArray) {
        System.out.println("Number = " + number);
    }
}

From source file:Main.java

public static void main(String[] args) {

    Vector<Integer> vec = new Vector<Integer>(4);

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

    // adding elements into the enumeration
    Enumeration e = vec.elements();

    // let us print all the elements available in enumeration
    System.out.println("Numbers in the enumeration are :- ");
    while (e.hasMoreElements()) {
        System.out.println("Number = " + e.nextElement());
    }
}