Here you can find the source of removeNulls(ArrayList
public static <E> void removeNulls(ArrayList<E> list)
//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); } } }