Example usage for java.util Vector size

List of usage examples for java.util Vector size

Introduction

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

Prototype

public synchronized int size() 

Source Link

Document

Returns the number of components in this vector.

Usage

From source file:Main.java

public static void main(String[] args) {

    Vector vec = new Vector(4);

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

    System.out.println(vec);
    System.out.println("Size of the vector: " + vec.size());

    // let us remove all the elements
    System.out.println("Removing all the elements");
    vec.removeAll(vec);
    System.out.println("Size of the vector: " + vec.size());
}

From source file:Main.java

public static void main(String[] args) {

    Vector vec = new Vector(4);

    vec.add(4);/* ww w.  j ava  2 s. com*/
    vec.add(3);
    vec.add(2);
    vec.add(1);

    System.out.println(vec);

    System.out.println("Size of the vector: " + vec.size());

    System.out.println("Removing all elements");
    // lets remove all the elements
    vec.removeAllElements();

    System.out.println("Now size of the vector: " + vec.size());
}

From source file:Main.java

public static void main(String[] args) {

    Vector vec = new Vector(4);

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

    System.out.println(vec);

    System.out.println("Size of the vector: " + vec.size());

    System.out.println("Removing all elements");
    // lets remove all the elements
    vec.removeElement(3);

    System.out.println("Now size of the vector: " + vec.size());
}

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);// w  w w. ja va2 s . co  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());
}

From source file:ListCaptureDevices.java

public static void main(String[] args) {

    /////////////////////////////////////////////////////////////
    // Query CaptureDeviceManager about ANY capture devices (null
    // format)//from ww w  . j  a  v a  2s  . co  m
    Vector info = CaptureDeviceManager.getDeviceList(null);
    if (info == null)
        System.out.println("No Capture devices known to JMF");
    else {
        System.out.println("The following " + info.size() + " capture devices are known to the JMF");
        for (int i = 0; i < info.size(); i++)
            System.out.println("\t" + (CaptureDeviceInfo) info.elementAt(i));
    }
}

From source file:com.benasmussen.tools.testeditor.ExtractorCLI.java

public static void main(String[] args) throws Exception {
    HelpFormatter formatter = new HelpFormatter();

    // cli options
    Options options = new Options();
    options.addOption(CMD_OPT_INPUT, true, "Input file");
    // options.addOption(CMD_OPT_OUTPUT, true, "Output file");

    try {/*from   w w w.  j a v  a2 s  .  c om*/

        // evaluate command line options
        CommandLineParser parser = new GnuParser();
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption(CMD_OPT_INPUT)) {
            // option value
            String optionValue = cmd.getOptionValue(CMD_OPT_INPUT);

            // input file
            File inputFile = new File(optionValue);

            // id extractor
            IdExtractor idExtractor = new IdExtractor(inputFile);
            Vector<Vector> data = idExtractor.parse();

            // // TODO implement output folder
            // if (cmd.hasOption(CMD_OPT_OUTPUT))
            // {
            // // file output
            // throw new Exception("Not implemented");
            // }
            // else
            // {
            // console output
            System.out.println("Id;Value");
            for (Vector vector : data) {
                StringBuilder sb = new StringBuilder();
                if (vector.size() >= 1) {
                    sb.append(vector.get(0));
                }
                sb.append(";");
                if (vector.size() >= 2) {
                    sb.append(vector.get(1));
                }
                System.out.println(sb.toString());
            }
            // }
        } else {
            throw new IllegalArgumentException();
        }

    } catch (ParseException e) {
        formatter.printHelp("ExtractorCLI", options);
    } catch (IllegalArgumentException e) {
        formatter.printHelp("ExtractorCLI", options);
    }
}

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;/*w  w w .ja va  2  s .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:Main.java

public static void main(String[] args) {

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

    vec.add(4);//w  ww .j  a v  a 2  s.com
    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:SortWithCollationKeys.java

public static void main(String[] args) {
    Vector<String> list = new Vector<String>();
    list.add("m");
    list.add("c");
    list.add("e");
    list.add("c");

    Collator collate = Collator.getInstance();

    CollationKey[] keys = new CollationKey[list.size()];

    for (int k = 0; k < list.size(); k++)
        keys[k] = collate.getCollationKey((String) list.elementAt(k));

    CollationKey tmp;//w w  w. j  a  va  2s  . co m
    for (int i = 0; i < keys.length; i++) {
        for (int j = i + 1; j < keys.length; j++) {
            if (keys[i].compareTo(keys[j]) > 0) {
                tmp = keys[i];
                keys[i] = keys[j];
                keys[j] = tmp;
            }
        }
    }
    for (int l = 0; l < keys.length; l++) {
        System.out.println(keys[l].getSourceString());
    }
}

From source file:Main.java

public static void main(String[] args) {
    Vector<String> v = new Vector<String>();
    v.add("1");/*w ww . j  av a 2  s.co  m*/
    v.add("2");
    v.add("3");

    ArrayList<String> arrayList = new ArrayList<String>();
    arrayList.add("4");
    arrayList.add("5");

    v.addAll(arrayList);

    for (int i = 0; i < v.size(); i++) {
        System.out.println(v.get(i));
    }
}