Example usage for java.util Vector add

List of usage examples for java.util Vector add

Introduction

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

Prototype

public synchronized boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this Vector.

Usage

From source file:Main.java

public static void main(String[] args) {

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

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

    vec.setElementAt(11, 2);

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

From source file:Main.java

public static void main(String[] args) {
    Vector<String> v = new Vector<String>();

    v.add("Z");
    v.add("B");//from ww  w .j a v  a2 s .com
    v.add("D");
    v.add("E");
    v.add("F");

    Collections.sort(v);
    System.out.println(v);

    int index = Collections.binarySearch(v, "D");
    System.out.println("Element found at : " + index);
}

From source file:Main.java

public static void main(String[] args) {
    Vector<String> v = new Vector<String>();
    v.add("A");
    v.add("B");/* ww w  . j a v a2s . com*/
    v.add("D");
    v.add("E");
    v.add("F");

    System.out.println(v);
    Enumeration e = v.elements();

    ArrayList<String> aList = Collections.list(e);
    System.out.println(aList);
}

From source file:Main.java

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

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

    System.out.println(vec);

    ListIterator<Integer> it = vec.listIterator(2);
    while (it.hasNext()) {
        System.out.println(it.next());
    }
}

From source file:Main.java

public static void main(String[] args) {
    // create an empty Vector vec   
    Vector<Integer> vec = new Vector<Integer>();

    vec.add(14);
    vec.add(13);//from ww w.j ava  2  s  . c  om
    vec.add(12);
    vec.add(11);
    vec.add(4);
    vec.add(3);
    vec.add(2);
    vec.add(1);

    // let us print the capacity of the vector
    System.out.println("Capacity of the vector is :" + vec.capacity());
}

From source file:Main.java

public static void main(String[] args) {

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

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

    System.out.println(vec);

    // add new element
    vec.addElement(12);

    System.out.println(vec);
}

From source file:Main.java

public static void main(String[] args) {

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

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

    // set 15 at 2nd index position
    vec.set(2, 15);

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

From source file:Main.java

public static void main(String[] args) {
    Vector<String> v = new Vector<String>();

    v.add("1");
    v.add("2");/*from   w  w  w  .j av  a2s . c  om*/
    v.add("3");
    v.add("4");
    v.add("5");

    v.setSize(3);

    for (String str : v) {
        System.out.println(str);
    }
    v.setSize(5);
    for (String str : v) {
        System.out.println(str);
    }
}

From source file:Main.java

public static void main(String[] args) {

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

    vec.add(4);
    vec.add(3);/*w  ww.  ja v  a  2  s .co  m*/
    vec.add(2);
    vec.add(1);

    // lets remove element at index 2
    System.out.println("Remove element at index 2");
    vec.removeElementAt(2);

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

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();
    arrayList.add("1");
    arrayList.add("2");
    arrayList.add("3");

    Vector<String> v = new Vector<String>();
    v.add("4");
    v.add("5");//from   www  .  j a  v a2s  .  com

    // insert all elements of Vector to ArrayList at index 1
    arrayList.addAll(1, v);

    for (String str : arrayList)
        System.out.println(str);
}