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() 

Source Link

Document

Constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {
    Vector<String> v = new Vector<String>();
    v.add("a");/*w w w  .j  ava2s . c  om*/
    v.add("b");
    v.add("java2s.com");

    Collection<String> col = v;
    Enumeration<String> e = Collections.enumeration(col);

    for (; e.hasMoreElements();) {
        Object o = e.nextElement();
        System.out.println(o);
    }
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    Vector<String> v = new Vector<String>();
    v.add("a");/*  w  ww  . j av a  2s .c om*/
    v.add("b");
    v.add("c");

    Collection<String> col = v;
    Enumeration<String> e = Collections.enumeration(col);

    for (; e.hasMoreElements();) {
        Object o = e.nextElement();
        System.out.println(o);
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    Vector vector = new Vector();
    vector.addElement(new Integer(5));
    vector.addElement(new Float(-14.14f));

    System.out.println(vector);//from  w  ww .  j  a va  2 s.com

    String s = new String("String to be inserted");
    vector.insertElementAt(s, 1);
    System.out.println(vector);

    vector.removeElementAt(2);
    System.out.println(vector);
}

From source file:Main.java

public static void main(String[] argv) {
    Vector rowData = new Vector();
    for (int i = 0; i < 1; i++) {
        Vector colData = new Vector(Arrays.asList("qq"));
        rowData.add(colData);/*  w  w  w .ja v  a 2 s  .  com*/
    }

    String[] columnNames = { "a" };

    Vector columnNamesV = new Vector(Arrays.asList(columnNames));

    JTable table = new JTable(rowData, columnNamesV);
    JFrame f = new JFrame();
    f.setSize(300, 300);
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:UncheckedExample.java

public static void main(String args[]) {
    Vector<Integer> intVector = new Vector<Integer>();
    Vector oldVector = new Vector();
    UncheckedExample ue = new UncheckedExample();

    // This is permitted
    oldVector = intVector;//www.  j av a  2 s .  c om
    // This causes an unchecked warning
    intVector = oldVector;
    // This is permitted
    ue.processIntVector(intVector);
    // This causes an unchecked warning
    ue.processIntVector(oldVector);
}

From source file:RemoveVector.java

public static void main(String args[]) {
    Vector v = new Vector();
    for (int i = 0, n = args.length; i < n; i++) {
        v.add(args[i]);//from  w ww .j  ava  2  s  . c  o m
    }
    System.out.println(removeAll(v, args[0]));
    System.out.println(v);
}

From source file:VectorBenchmark1.java

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

    long start = System.currentTimeMillis();
    for (int i = 0; i < MaxSize; i++)
        v.add(new Integer(i));
    long end = System.currentTimeMillis();
    System.out.println("Allocating vector elements: " + (end - start) + " milliseconds");

    Integer[] integerArray = new Integer[1];
    start = System.currentTimeMillis();
    for (int i = 0; i < MaxSize; i++) {
        if (i >= integerArray.length) {
            Integer[] b = new Integer[i * 2];
            System.arraycopy(integerArray, 0, b, 0, integerArray.length);
            integerArray = b;//from  w w w . j av  a  2 s .  co  m
        }
        integerArray[i] = new Integer(i);
    }
    end = System.currentTimeMillis();
    System.out.println("Allocating array elements:  " + (end - start) + " milliseconds");

    start = System.currentTimeMillis();
    for (int j = 0; j < NTRIES; j++)
        for (int i = 0; i < MaxSize; i++) {
            Integer r = (Integer) v.get(i);
            v.set(i, new Integer(r.intValue() + 1));
        }
    end = System.currentTimeMillis();
    System.out.println("Accessing vector elements:  " + (end - start) + " milliseconds");

    start = System.currentTimeMillis();
    for (int j = 0; j < NTRIES; j++)
        for (int i = 0; i < MaxSize; i++) {
            Integer r = integerArray[i];
            integerArray[i] = new Integer(r.intValue() + 1);
        }
    end = System.currentTimeMillis();
    System.out.println("Accessing array elements:   " + (end - start) + " milliseconds");
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    Vector theStreams = new Vector();

    for (int i = 0; i < args.length; i++) {
        FileInputStream fin = new FileInputStream(args[i]);
        theStreams.addElement(fin);/*from   w  w w. j a v a 2 s . co m*/
    }

    InputStream in = new SequenceInputStream(theStreams.elements());
    for (int i = in.read(); i != -1; i = in.read()) {
        System.out.write(i);
    }
}

From source file:FindVector2.java

public static void main(String args[]) {
    Vector v = new Vector();
    for (int i = 0, n = members.length; i < n; i++) {
        v.add(members[i]);//from  ww  w.j a  v  a  2 s  . c o m
    }
    System.out.println(v);
    System.out.println("Contains Society?: " + v.contains("Society"));
    System.out.println("Contains Waldo?: " + v.contains("Waldo"));
    System.out.println("Where's Waldo?: " + v.indexOf("Waldo"));
    System.out.println("Where's Thoreau?: " + v.indexOf("Thoreau"));
    System.out.println("Where's Thoreau from end?: " + v.lastIndexOf("Thoreau"));
    int index = 0;
    int length = v.size();
    while ((index < length) && (index >= 0)) {
        index = v.indexOf("Thoreau", index);
        if (index != -1) {
            System.out.println(v.get(index));
            index++;
        }
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    Vector v = new Vector();
    for (int i = 0, n = members.length; i < n; i++) {
        v.add(members[i]);//from   w w w  . j av a2s .c o m
    }
    System.out.println(v);
    System.out.println("Contains A?: " + v.contains("A"));
    System.out.println("Where's A?: " + v.indexOf("A"));
    System.out.println("Where's B from end?: " + v.lastIndexOf("B"));
    int index = 0;
    int length = v.size();
    while ((index < length) && (index >= 0)) {
        index = v.indexOf("C", index);
        if (index != -1) {
            System.out.println(v.get(index));
            index++;
        }
    }
}