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

private static List<String> removeListItem(ArrayList arrlist, String s) {
    arrlist.remove(s);
    return arrlist;
}

From source file:Main.java

public static <T> ArrayList<T> merge(Collection<T> l1, Collection<T> l2, T toRemove) {
    ArrayList<T> al = union(l1, l2);
    al.remove(toRemove);
    return al;/*www .  j a  v a  2 s . c  o  m*/
}

From source file:Main.java

public static boolean compareList(List<?> l1, List<?> l2) {
    // make a copy of the list so the original list is not changed, and remove() is supported
    ArrayList<?> cp = new ArrayList<>(l1);
    for (Object o : l2) {
        if (!cp.remove(o)) {
            return false;
        }//  w  w  w.  j  ava 2s  .  co m
    }
    return cp.isEmpty();
}

From source file:Main.java

public static void removeElementsFromIndexToEnd(ArrayList list, int index) {
    for (int i = list.size() - 1; i >= index; i--)
        list.remove(i);
}

From source file:Main.java

public static <T> ArrayList<T> subtract(Collection<T> l1, Collection<T> l2) {
    ArrayList<T> al = new ArrayList<T>();
    al.addAll(l1);/*from  w ww.ja  v  a  2  s .c  o  m*/
    for (T item : l2) {
        al.remove(item);
    }
    return al;
}

From source file:Main.java

public static <T> T[] remove(T[] current, T queueId) {
    ArrayList<T> asList = asList(current);
    asList.remove(queueId);
    T[] result = current.clone();/*w w  w .  j a  va2s . com*/
    return asList.toArray(result);
}

From source file:Main.java

/**
 * Returns a new {@link Collection} containing <tt><i>a</i> - <i>b</i></tt>.
 * The cardinality of each element <i>e</i> in the returned {@link Collection}
 * will be the cardinality of <i>e</i> in <i>a</i> minus the cardinality
 * of <i>e</i> in <i>b</i>, or zero, whichever is greater.
 *
 * @param a  the collection to subtract from, must not be null
 * @param b  the collection to subtract, must not be null
 * @return a new collection with the results
 * @see Collection#removeAll/*from   ww  w. j  a  v  a 2s  . c om*/
 */
public static Collection subtract(final Collection a, final Collection b) {
    ArrayList list = new ArrayList(a);
    for (Iterator it = b.iterator(); it.hasNext();) {
        list.remove(it.next());
    }
    return list;
}

From source file:Main.java

public static <T> ArrayList<T> remove(ArrayList<T> cur, T val) {
    if (cur == null) {
        return null;
    }/*from   www .  j av a 2s.  co  m*/
    cur.remove(val);
    if (cur.isEmpty()) {
        return null;
    } else {
        return cur;
    }
}

From source file:Main.java

/**
 * Returns a {@link Collection} containing <tt><i>a</i> - <i>b</i></tt>. The
 * cardinality of each element <i>e</i> in the returned {@link Collection}
 * will be the cardinality of <i>e</i> in <i>a</i> minus the cardinality of
 * <i>e</i> in <i>b</i>, or zero, whichever is greater.
 * /*from w  ww.j av a  2s  . c o  m*/
 * @see Collection#removeAll
 */
public static Collection subtract(final Collection a, final Collection b) {
    ArrayList list = new ArrayList(a);
    Iterator it = b.iterator();
    while (it.hasNext()) {
        list.remove(it.next());
    }
    return list;
}

From source file:Main.java

public static boolean equals(List list1, List list2) {
    if (list1 == list2) {
        //both are the same
        return true;
    }//from   ww w .  ja v  a 2 s .  c  o m
    if (list1 == null || list2 == null) {
        // we know both aren't null, so if one is null them obviously false
        return false;
    }
    if (list1.size() != list2.size()) {
        return false;
    }
    if (list1.isEmpty()) {
        return true;
    }
    ArrayList<?> arr = new ArrayList<>(list2);
    for (Object obj : list1) {
        if (!arr.remove(obj)) {
            return false;
        }
    }
    return true;
}