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

/**
 * Removes the given object from the list using reference equality, not equals()
 * @param list/*from   ww w . j  a va 2s. com*/
 * @param object
 * @return
 */
public static <T> boolean removeByReference(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) {
            list.remove(i);
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static void removeStringFromArrayList(String strItem, ArrayList<String> alItems) {

    // cycles on the arraylist
    for (int j = 0; j < alItems.size(); j++) {

        // gets the j-thg item
        String strValue = alItems.get(j);

        // if the j-th item is equal to the passed one
        if (strValue.equals(strItem)) {

            // removes it
            alItems.remove(j);//from   w  w w.j  av  a2  s. com

            // and returns
            return;
        }

    }

}

From source file:Main.java

public static String getCommandInputList(ArrayList<String> commands) {
    if (commands == null || commands.size() == 0) {
        return "";
    }/*from  ww  w .j a v  a  2s  .c  o m*/

    StringBuilder sb = new StringBuilder();
    for (String commandPattern : commands) {
        String[] cmdSplit = commandPattern.split("~");
        if (cmdSplit.length != 3) {
            Log.e("DebugGhost", "Cannot read command pattern '" + commandPattern + "', skipping ...");
            continue;
        }
        if (cmdSplit[2].contains("[") == false && cmdSplit[2].contains("]") == false) {
            continue;
        }

        String realValue = cmdSplit[2].replace("[", "").replace("]", "");

        sb.append("<div class=\"input-group\" style=\"margin-bottom: 5px;\">");
        sb.append("<span class=\"input-group-btn\">");
        sb.append("<button class=\"btn btn-default\" type=\"button\" onclick=\"postCommandValue('/commands/");
        sb.append(cmdSplit[1]);
        sb.append("','");
        sb.append(cmdSplit[1]);
        sb.append("');\" >");
        sb.append(cmdSplit[0]);
        sb.append("</button></span>");
        sb.append("<input id=\"" + cmdSplit[1]
                + "\" type=\"text\" class=\"form-control\" placeholder=\"set your value here\" value=\""
                + realValue + "\">");
        sb.append("</div>");
    }

    return sb.toString();
}

From source file:Main.java

/**
 * This is based on bit shifting (using base128()).
 * Returns array of bytes./*from  w w w .  ja va2 s . c o  m*/
 * @param val
 * @return
 */
public static byte[] toBase_128(BigInteger val) {
    ArrayList<Integer> al = base128(val);
    byte[] result = new byte[al.size()];
    for (int k = 0; k < result.length; k++)
        result[k] = al.get(k).byteValue();
    ;
    return result;
}

From source file:Main.java

public static int countCommElmts(ArrayList<String> u, ArrayList<String> v) {
    ArrayList<String> listOne = new ArrayList<String>();
    listOne.addAll(u);//from w w w  .ja v a 2s .co m
    listOne.retainAll(v);
    return listOne.size();
}

From source file:Main.java

/**
 * creates a string from an arraylist/*from  w w  w. j  a  va 2s . c  o m*/
 * 
 * @param alValues the values to be concatenated
 * @param strSeparator the separator between one element and the other
 * @return the string with the values seaparated by the strSeparator
 */
public static String[] getStringArrayFromArrayList(ArrayList<String> alValues) {

    // inits the buffer
    String[] strValues = new String[alValues.size()];

    // cycles on the values of the AL
    for (int j = 0; j < alValues.size(); j++) {

        // appends the j-th vlaur to the buffer
        strValues[j] = alValues.get(j);
    }

    // and returns it
    return strValues;
}

From source file:Main.java

public static void printLeagues(ArrayList<String> leagues) {
    System.out.println("Here are the list of leagues possible:");
    for (int i = 0; i < leagues.size(); i++) {
        System.out.println((i + 1) + ": " + leagues.get(i));
    }/*from   w w w  .  ja  v  a2s. co  m*/
}

From source file:Main.java

public static void printAccounts(ArrayList<String> accounts) {
    System.out.println("Here are the list of accounts possible:");
    for (int i = 0; i < accounts.size(); i++) {
        System.out.println((i + 1) + ": " + accounts.get(i));
    }//from ww w  .  j ava 2  s . c  o  m
}

From source file:Main.java

/**** Check if the value is exist in the list ****/
public static boolean isExistInList(ArrayList<String> list, String value) {
    if (list == null)
        return false;
    for (int i = 0; i < list.size(); i++) {
        if (list.get(i).equals(value)) {
            return true;
        }/*from   ww  w .j  av a 2  s. c  om*/
    }
    return false;
}

From source file:Main.java

private static void fillCombinations(ArrayList<Boolean> current, ArrayList<ArrayList<Boolean>> result, int n) {
    // base case//  w w  w  .jav a 2 s.  c o m
    if (current.size() == n) {
        result.add(current);
    } else {
        // add a zero
        ArrayList<Boolean> addZero = new ArrayList(current);
        addZero.add(false);
        fillCombinations(addZero, result, n);

        // add a one
        ArrayList<Boolean> addOne = new ArrayList(current);
        addOne.add(true);
        fillCombinations(addOne, result, n);

    }
}