Java Utililty Methods Collection Remove

List of utility methods to do Collection Remove

Description

The list of methods to do Collection Remove are organized into topic(s).

Method

ListgetItemsStartingWith(Collection items, String prefix, boolean removePrefix)
get Items Starting With
List<String> rtn = new ArrayList<String>();
for (String s : items) {
    if (s.startsWith(prefix)) {
        if (removePrefix) {
            s = s.substring(prefix.length());
        rtn.add(s);
return rtn;
CollectiongetRemovedItems(Collection oldValues, Collection newValues)
get Removed Items
return getAddedItems(newValues, oldValues);
Collectionminus(Collection primaryCollection, Collection toBeRemovedCollection, Collection target)
Return a new Collection containing the elements of Collection a minus elements of Collection b
target.clear();
for (T elem : primaryCollection) {
    if (!toBeRemovedCollection.contains(elem)) {
        target.add(elem);
return target;
voidremove(Collection c, Object o)
remove
c.remove(o);
booleanremove(Collection collection, Object object)
remove
boolean removed = false;
Iterator it = collection.iterator();
while (it.hasNext()) {
    Object o = it.next();
    if (o.equals(object)) {
        removed = true;
        it.remove();
        break;
...
Collectionremove(Collection p_collection, int p_index, int p_numberOfObjects)
Removes the element at the specified position in the collection.
if (p_collection == null) {
    return null;
List returnList = new ArrayList(p_collection.size() - p_numberOfObjects);
Iterator it = p_collection.iterator();
for (int i = 0; it.hasNext(); i++) {
    if (i < p_index || i >= p_index + p_numberOfObjects) {
        returnList.add(it.next());
...
booleanremove(Collection col, T value)
remove
if (col == null) {
    return false;
return col.remove(value);
Listremove(Collection collection, final int count)
Removes the specified number of elements from the collection, returns them as a list.
List<T> list = new ArrayList<T>();
while (list.size() < count && collection.size() > 0) {
    T value = collection.iterator().next();
    list.add(value);
    collection.remove(value);
return list;
voidremove(Collection collection, T... items)
Removes items from collection
for (T t : items) {
    collection.remove(t);
booleanremove(final Collection c, final Object elem)
remove
return (c != null) && c.remove(elem);