Example usage for java.util ArrayList remove

List of usage examples for java.util ArrayList remove

Introduction

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

Prototype

public boolean remove(Object o) 

Source Link

Document

Removes the first occurrence of the specified element from this list, if it is present.

Usage

From source file:Main.java

public static <T> List<T> subtract(Collection<T> a, Collection<T> b) {
    ArrayList list = new ArrayList(a);
    Iterator i$ = b.iterator();/*w  w w  .  ja  va2 s. c  o m*/

    while (i$.hasNext()) {
        Object element = i$.next();
        list.remove(element);
    }

    return list;
}

From source file:com.openquartz.glassmemo.Utils.java

/**
 * Deletes an item from the list stored in shared preferences 
 * @param index/*from  w ww  . jav a2s .  co m*/
 * @param context
 * @param key
 */
public static void deleteMemoAtIndex(int index, Context context, String key) {
    ArrayList<String> memoList = new ArrayList<String>(getStringArrayPref(context, key));
    memoList.remove(index);
    commitNewMemoList(context, key, memoList);
}

From source file:com.jdy.ddj.common.utils.Collections3.java

public static <T> List<T> subtract(final Collection<T> a, final Collection<T> b) {
    ArrayList<T> list = new ArrayList<T>(a);
    for (Iterator it = b.iterator(); it.hasNext();) {
        list.remove(it.next());
    }//from w w w .  ja v  a 2 s  .co  m
    return list;
}

From source file:com.framework.infrastructure.utils.Collections3.java

/**
 * a-b./*from  w  ww . j av  a  2 s. c  o m*/
 */
public static <T> List<T> subtract(final Collection<T> a, final Collection<T> b) {
    ArrayList<T> list = new ArrayList<T>(a);
    for (Object element : b) {
        list.remove(element);
    }
    return list;
}

From source file:Main.java

public static String evalConcat(Node n, String delimiter, XPathExpression... exprs)
        throws XPathExpressionException {
    ArrayList<String> results = new ArrayList<String>();
    for (XPathExpression expr : exprs) {
        results.add(orEmptyStr(expr, n));
    }//  w w  w.  j  a  va  2s.co  m

    while (results.remove(""))
        ;

    String retn = "";

    for (String s : results) {
        retn += s;
        if (results.indexOf(s) != results.size() - 1) {
            retn += delimiter;
        }
    }

    return retn;
}

From source file:Main.java

public static <E> void removeDuplicate(ArrayList<E> list) {
    for (int i = 0; i < list.size() - 1; i++) {
        for (int j = list.size() - 1; j > i; j--) {
            if (list.get(j).equals(list.get(i))) {
                list.remove(j);
            }/*from  www  . java  2 s .  c  om*/
        }
    }
}

From source file:Main.java

private static <T> boolean removeAllFromArrayList(ArrayList<T> collection, Collection<?> toRemove) {
    boolean result = false;
    for (int i = collection.size(); --i >= 0;)
        if (toRemove.contains(collection.get(i))) {
            collection.remove(i);
            result = true;//w  w  w. j a v  a2s .c om
        }
    return result;
}

From source file:Main.java

public static void unRevokePermission(String packageName, String permission, Context ctx) {
    String[] rPerms = getRevokedPerms(packageName, ctx);
    if (rPerms == null)
        rPerms = new String[0];
    ArrayList<String> revokedPerms = new ArrayList<String>();
    revokedPerms.addAll(Arrays.asList(rPerms));
    if (revokedPerms.contains(permission)) {
        revokedPerms.remove(permission);
        String[] permsToRevoke = new String[revokedPerms.size()];
        revokedPerms.toArray(permsToRevoke);
        setRevokedPermissions(packageName, permsToRevoke, ctx);
    }//from w ww  .j  ava 2 s . c o  m
}

From source file:Main.java

/**
 * Removes the given object from the list using reference equality, not equals()
 * @param list//from w ww .ja v  a2s .c om
 * @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 <T> ArrayList<T> shuffle(ArrayList<T> population, int sample) {
    ArrayList<T> newList = new ArrayList<T>();
    ArrayList<T> ret = new ArrayList<T>();
    newList.addAll(population);// www.  j av a  2s  . com

    Collections.shuffle(newList);
    ret.addAll(newList);
    for (int i = sample; i < ret.size(); i++) {
        ret.remove(i);
        i--;
    }
    newList.clear();
    return ret;
}