Example usage for java.util Vector addElement

List of usage examples for java.util Vector addElement

Introduction

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

Prototype

public synchronized void addElement(E obj) 

Source Link

Document

Adds the specified component to the end of this vector, increasing its size by one.

Usage

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));
    vector.addElement(new String("Hello"));

    Enumeration e = vector.elements();
    while (e.hasMoreElements()) {
        Object obj = e.nextElement();
        System.out.println(obj);/*  w  w w.  j  a v a 2 s  .  c o  m*/
    }
}

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 www .  j a v a2  s . c  o m*/

    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:SafeVectorCopy.java

public static void main(String[] args) {
    Vector vect = new Vector();
    vect.addElement("Synchronization");
    vect.addElement("is");
    vect.addElement("important");

    String[] word;//from   w  w  w  . j  a  v  a 2s  .c om

    synchronized (vect) {
        int size = vect.size();
        word = new String[size];

        for (int i = 0; i < word.length; i++) {
            word[i] = (String) vect.elementAt(i);
        }
    }

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

From source file:MainClass.java

public static void main(String args[]) {

    Vector v = new Vector();

    for (int i = 0; i < 5; i++) {
        v.addElement(new Double(5));
    }/*from   w ww.j  av a 2s. c o  m*/

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

From source file:InputStreamEnumerator.java

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

    int c;/* w ww  .  j  a v a  2s . c o  m*/
    Vector<String> files = new Vector<String>();

    files.addElement("c:\\autoexec.bat");
    files.addElement("c:\\config.sys");
    InputStreamEnumerator e = new InputStreamEnumerator(files);
    InputStream input = new SequenceInputStream(e);

    while ((c = input.read()) != -1) {
        System.out.print((char) c);
    }

    input.close();
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Vector months = new Vector();
    JList list = new JList(months);

    months.addElement("January");
    months.addElement("December");

    frame.add(new JScrollPane(list));

    frame.setSize(300, 200);/*from  w ww . j a v  a2  s. co m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Vector<String> rowOne = new Vector<String>();
    rowOne.addElement("Row1-Column1");
    rowOne.addElement("Row1-Column2");
    rowOne.addElement("Row1-Column3");

    Vector<String> rowTwo = new Vector<String>();
    rowTwo.addElement("Row2-Column1");
    rowTwo.addElement("Row2-Column2");
    rowTwo.addElement("Row2-Column3");

    Vector<Vector> rowData = new Vector<Vector>();
    rowData.addElement(rowOne);/*w  w  w.jav  a 2 s . co m*/
    rowData.addElement(rowTwo);

    Vector<String> columnNames = new Vector<String>();
    columnNames.addElement("Column One");
    columnNames.addElement("Column Two");
    columnNames.addElement("Column Three");
    JTable table = new JTable(rowData, columnNames);

    JScrollPane scrollPane = new JScrollPane(table);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);

}

From source file:SetViewportPosition.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Vector<String> rowOne = new Vector<String>();
    rowOne.addElement("Row1-Column1");
    rowOne.addElement("Row1-Column2");
    rowOne.addElement("Row1-Column3");

    Vector<String> rowTwo = new Vector<String>();
    rowTwo.addElement("Row2-Column1");
    rowTwo.addElement("Row2-Column2");
    rowTwo.addElement("Row2-Column3");

    Vector<Vector> rowData = new Vector<Vector>();
    rowData.addElement(rowOne);//from w ww .ja  v  a 2s .  co m
    rowData.addElement(rowTwo);

    Vector<String> columnNames = new Vector<String>();
    columnNames.addElement("Column One");
    columnNames.addElement("Column Two");
    columnNames.addElement("Column Three");
    JTable table = new JTable(rowData, columnNames);

    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.getViewport().setViewPosition(new Point(0, 0));
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Vector<String> rowOne = new Vector<String>();
    rowOne.addElement("Row1-Column1");
    rowOne.addElement("Row1-Column2");
    rowOne.addElement("Row1-Column3");

    Vector<String> rowTwo = new Vector<String>();
    rowTwo.addElement("Row2-Column1");
    rowTwo.addElement("Row2-Column2");
    rowTwo.addElement("Row2-Column3");

    Vector<Vector> rowData = new Vector<Vector>();
    rowData.addElement(rowOne);//from www  .  j a  v a2 s  . c o m
    rowData.addElement(rowTwo);

    Vector<String> columnNames = new Vector<String>();
    columnNames.addElement("Column One");
    columnNames.addElement("Column Two");
    columnNames.addElement("Column Three");
    JTable table = new JTable(rowData, columnNames);

    table.setValueAt("aa", 0, 0);

    JScrollPane scrollPane = new JScrollPane(table);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);

}

From source file:Utilities.java

public static void main(String[] args) {
    List list = Arrays.asList("one Two three Four five six one".split(" "));
    System.out.println(list);//from   w  w w.ja va 2  s  .  c  o  m
    System.out.println("max: " + Collections.max(list));
    System.out.println("min: " + Collections.min(list));
    AlphabeticComparator comp = new AlphabeticComparator();
    System.out.println("max w/ comparator: " + Collections.max(list, comp));
    System.out.println("min w/ comparator: " + Collections.min(list, comp));
    List sublist = Arrays.asList("Four five six".split(" "));
    System.out.println("indexOfSubList: " + Collections.indexOfSubList(list, sublist));
    System.out.println("lastIndexOfSubList: " + Collections.lastIndexOfSubList(list, sublist));
    Collections.replaceAll(list, "one", "Yo");
    System.out.println("replaceAll: " + list);
    Collections.reverse(list);
    System.out.println("reverse: " + list);
    Collections.rotate(list, 3);
    System.out.println("rotate: " + list);
    List source = Arrays.asList("in the matrix".split(" "));
    Collections.copy(list, source);
    System.out.println("copy: " + list);
    Collections.swap(list, 0, list.size() - 1);
    System.out.println("swap: " + list);
    Collections.fill(list, "pop");
    System.out.println("fill: " + list);
    List dups = Collections.nCopies(3, "snap");
    System.out.println("dups: " + dups);
    // Getting an old-style Enumeration:
    Enumeration e = Collections.enumeration(dups);
    Vector v = new Vector();
    while (e.hasMoreElements())
        v.addElement(e.nextElement());
    // Converting an old-style Vector
    // to a List via an Enumeration:
    ArrayList arrayList = Collections.list(v.elements());
    System.out.println("arrayList: " + arrayList);

}