Java ArrayList Remove removeNulls(ArrayList list)

Here you can find the source of removeNulls(ArrayList list)

Description

remove Nulls

License

Open Source License

Declaration

public static <E> void removeNulls(ArrayList<E> list) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

public class Main {
    public static <E> void removeNulls(ArrayList<E> list) {
        int pos = 0;
        for (int i = 0; i < list.size(); i++) {
            E current = list.get(i);/*  ww  w  .j  ava2s.  c  om*/
            if (current != null) {
                if (i != pos) {
                    list.set(pos, current);
                }

                pos++;
            }
        }

        for (int i = list.size() - 1; i >= pos; i--) {
            list.remove(i);
        }
    }
}

Related

  1. removeDuplicateWithOrder(List arrayList)
  2. removeElementsFromIndexToEnd(ArrayList list, int index)
  3. removeExtraPunctuation(String line, int startChar, ArrayList indices)
  4. removeIndex(ArrayList arr, ArrayList idNames)
  5. removeLastValues(final ArrayList v, final int remove)
  6. removeRepeatedElems(ArrayList list)