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 Vector nullIfEmpty(Vector v) {
    return (v == null ? null : (v.size() == 0 ? null : v));
}

From source file:Main.java

/**
 * Add all elements to the given vector.
 * @param vec/*w  w w.  j a  va2 s .com*/
 * @param elems
 */
public static void addAll(final Vector vec, final Vector elems) {
    for (int i = 0; i < elems.size(); i++) {
        vec.addElement(elems.elementAt(i));
    }
}

From source file:Main.java

public static <K> K setElementAt(Vector<K> vec, int index, K value) {
    K retVal;/*w ww .j  a  v  a 2s .c o  m*/
    if (vec.size() <= index) {
        vec.setSize(index + 10);
        retVal = null;
    } else
        retVal = vec.elementAt(index);
    vec.setElementAt(value, index);
    return retVal;
}

From source file:Main.java

public static Object[][] to2DArray(Vector<Vector> towDVector) {
    Object[][] towDArray = new Object[towDVector.size()][];
    for (int i = 0; i < towDVector.size(); i++) {
        Vector row = (Vector) towDVector.elementAt(i);

        towDArray[i] = row.toArray();/*from ww  w .  j  a v  a 2s.  c o  m*/
    }
    return towDArray;
}

From source file:Main.java

public static void deleteAllFiles(Vector filesToDelete) {
    for (int i = 0; i < filesToDelete.size(); i++) {
        ((File) filesToDelete.get(i)).delete();
    }//w w  w  .  j  a  v  a 2s . c o  m
}

From source file:Main.java

/**
 * @param first  First Integer Vector to be merged
 * @param second Second Integer Vector to be merged
 * @return single merged int array of first and second
 *//*w ww  .  j  a  va 2 s . c  om*/
public static int[] mergeIntegerVectorsInArray(Vector<Integer> first, Vector<Integer> second) {
    int resultLength = first.size() + second.size();
    int[] result = new int[resultLength];
    int i = 0;
    for (; i < first.size(); ++i) {
        result[i] = first.elementAt(i);
    }
    for (; i < resultLength; ++i) {
        result[i] = second.elementAt(i - first.size());
    }
    return result;
}

From source file:Main.java

/**
 * Method getHashMapFromVector./*  w w w.  ja va2 s. c  o  m*/
 * @param vector Vector
 * @return HashMap
 */
public static HashMap getHashMapFromVector(Vector vector) {
    HashMap hashMap = new HashMap(vector.size());

    for (int i = 0; i < vector.size(); i++) {
        hashMap.put(vector.elementAt(i), vector.elementAt(i));
    }

    return hashMap;
}

From source file:Main.java

public static Hashtable contarElementos(Vector list) {
    Hashtable hash = new Hashtable();

    for (int i = 0; i < list.size(); i++) {
        Object key = list.elementAt(i);
        if (hash.containsKey(key)) {
            Integer qtde = new Integer(((Integer) hash.get(key)).intValue() + 1);
            hash.put(key, qtde);//from   w ww  . j a v  a  2 s.c om
        } else {
            hash.put(key, new Integer(1));
        }
    }

    return hash;
}

From source file:Main.java

/**
 * Method getHashtableFromVector.//from ww w .  j a  v  a2 s .com
 * @param vector Vector
 * @return Hashtable
 */
public static Hashtable getHashtableFromVector(Vector vector) {
    Hashtable hashtable = new Hashtable(vector.size());

    for (int i = 0; i < vector.size(); i++) {
        hashtable.put(vector.elementAt(i), vector.elementAt(i));
    }

    return hashtable;
}

From source file:Main.java

public static Hashtable<Integer, Set<Integer>> getNodeMembership(Hashtable<Integer, Set<Integer>> nIDComVH,
        final Vector<Set<Integer>> cmtyVV) {
    for (int i = 0; i < cmtyVV.size(); i++) {
        int CID = i;
        for (Integer NID : cmtyVV.get(i)) {
            if (nIDComVH.containsKey(NID)) {
                Set<Integer> x = nIDComVH.get(NID);
                x.add(CID);/*from ww w  .  j  a  v  a 2 s .c  o  m*/
            } else {
                Set<Integer> x = new HashSet<Integer>();
                x.add(CID);
                nIDComVH.put(NID, x);
            }

        }
    }
    return nIDComVH;
}