Example usage for java.util ArrayList size

List of usage examples for java.util ArrayList size

Introduction

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

Prototype

int size

To view the source code for java.util ArrayList size.

Click Source Link

Document

The size of the ArrayList (the number of elements it contains).

Usage

From source file:Main.java

public static <T> int getFreq(ArrayList<ArrayList<T>> a, ArrayList<T> b) {
    int res = 0;//www .j  av a 2s  .  c om
    for (int i = 0; i < a.size(); i++) {
        if (isContain(a.get(i), b)) {
            res++;
        }
    }
    return res;
}

From source file:Main.java

private static boolean isValidSubString(ArrayList<String> list, String token) {
    if (list != null) {
        for (int i = 0; i < list.size(); ++i) {
            if (!((String) list.get(i)).startsWith(token)) {
                return false;
            }/*w  ww. j a v a 2 s .  c o m*/
        }

        return true;
    } else {
        return false;
    }
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static String implode(ArrayList ary, String delim) {
    String out = "";
    for (int i = 0; i < ary.size(); i++) {
        //if (ary.get(i)!=null) {
        out += (String) ary.get(i);
        if (i != ary.size() - 1) {
            out += delim;//from ww w .  ja v a  2s .  c  om
        }

        //}
    }
    return out;
}

From source file:Main.java

public static double getMindouble(ArrayList<Double> arr) {
    double min = Double.MAX_VALUE;

    for (int i = 0; i < arr.size(); i++) {
        double d = arr.get(i);
        if (d < min)
            min = d;//from  w w w .ja v  a  2 s  .c o m
    }

    return min;
}

From source file:Main.java

public static String arrayListToCsv(ArrayList<String> values) {
    StringBuilder csv = new StringBuilder();

    for (int i = 0; i < values.size(); i++) {
        csv.append(values.get(i));//from  ww w.j  a  va  2  s.co  m
        if (i < values.size() - 1) {
            csv.append(",");
        }
    }

    return csv.toString();
}

From source file:Main.java

public static HashMap<String, Integer> getMostFrequentDestination(ArrayList<String> destination) {
    System.out.println("ARRAYLIST INPUT! : " + destination.size());
    HashMap<String, Integer> temp = new HashMap<String, Integer>();
    for (String d : destination) {
        if (temp.containsKey(d)) {
            temp.put(d, temp.get(d) + 1);
        } else {//  ww w  . j a v  a  2  s .c o m
            temp.put(d, 1);
        }
    }
    return temp;
}

From source file:Main.java

/**
 * Combine messages in an array and put a size header before each message
 * @param array/*w  w  w  .  j  a  va 2s.  co  m*/
 * @return
 */
public static byte[] compileMessages(ArrayList<byte[]> array) {

    int bufferSize = 0;
    for (int i = 0; i < array.size(); i++) {
        byte[] thisByte = array.get(i);
        bufferSize += (4 + thisByte.length);
    }

    byte[] buffer = new byte[bufferSize];

    int pointer = 0; // used to index the next empty byte to fill
    for (int i = 0; i < array.size(); i++) {
        int thisSize = array.get(i).length;
        System.arraycopy(ByteBuffer.allocate(4).putInt(thisSize).array(), 0, buffer, pointer, 4);
        System.arraycopy(array.get(i), 0, buffer, pointer + 4, thisSize);
        pointer += (4 + thisSize);
    }

    return buffer;
}

From source file:Main.java

public static int countCommElmts(ArrayList<Integer> newScores1, ArrayList<Integer> newScores2) {
    int count = 0;
    for (int i = 0; i < newScores1.size(); i++) {
        if (newScores1.get(i) == newScores2.get(i))
            count++;//from ww w.  j av a 2 s  .  c  o m
    }
    return count;
}

From source file:Main.java

/**
 * Adds the object to the list if it does not already exist
 * @param list/* w w w. j  a v  a2  s. com*/
 * @param object
 * @return
 */
public static <T> boolean containsByReference(ArrayList<T> list, T object) {
    if (list == null)
        return false;
    int size = list.size();
    for (int i = 0; i < size; i++) {
        if (list.get(i) == object) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static String listToString(ArrayList<String> list, String flag) {
    String strMsg = "";
    int listSize = list.size();
    if (listSize > 0) {
        for (int i = 0; i < listSize; i++) {
            if (i == listSize - 1) {
                strMsg = strMsg + list.get(i).toString();
            } else {
                strMsg = strMsg + list.get(i).toString() + flag;
            }// w  w  w .  j  av  a2 s.  co  m
        }
    } else {
        strMsg = "";
    }
    return strMsg;
}