Java Utililty Methods List Remove

List of utility methods to do List Remove

Description

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

Method

voidremoveAll(List idxs, List values)
Removes all specified positions (which msut be given in ascending order) from the list.
int removed = 0;
for (int idx : idxs) {
    values.remove(idx - removed);
    removed++;
ListremoveAll(List strings, String string)
Removes all occurences of a String from a List .
if (strings == null) {
    throw new IllegalArgumentException("List<String> cannot be null");
if (string == null) {
    throw new IllegalArgumentException("String cannot be null");
List<String> list = new ArrayList<>(strings);
Iterator<String> iterator = list.iterator();
...
voidremoveAll(List list, List indexes)
Removes from the given list the elements at the given indexes.
if (list == null || indexes == null) {
    return;
Collections.sort(indexes, Collections.reverseOrder());
for (Integer index : indexes) {
    list.remove((int) index);
ListremoveAll(List toRemoveFrom, Collection elementsToRemove)
Convenient method to remove elements from a collection.
ArrayList<T> subtract = new ArrayList<>(toRemoveFrom);
subtract.removeAll(elementsToRemove);
return subtract;
booleanremoveAllNull(List list)
Removes all the null objects from the list
return list.removeIf((e) -> (null == e));
voidremoveAllNulls(List list)
This method removes all nulls from the given List.
while (list.remove(null))
    ;
ListremoveBlankLine(List lines)
remove Blank Line
List<String> result = new ArrayList<String>();
for (String line : lines) {
    if (line == null) {
        continue;
    String temp = line.trim();
    if (temp.length() == 0) {
        continue;
...
voidremoveByRef(List list, Object obj)
remove By Ref
int index = indexOfByRef(list, obj);
if (index >= 0) {
    list.remove(index);
voidremoveElement(T element, List list)
remove Element
if (list != null)
    list.remove(element);
ListremoveElementsFromList(List inputList, List elementsToRemove)
remove Elements From List
if (elementsToRemove == null) {
    return inputList;
List<T> filteredList = new ArrayList<T>(inputList);
for (Object objectToRemove : elementsToRemove) {
    for (int i = 0; i < filteredList.size(); i++) {
        if (filteredList.get(i).equals(objectToRemove)) {
            filteredList.remove(i);
...