Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; public class Main { /** * Creates new collection that does not contain nulls. Does not change input * collection. It uses raw collection - not parameterized. * {@link SuppressWarnings} annotation is added to avoid IDE to report * rawtypes and unchecked warnings. * * @param c * raw collection to create cleaned collection from. * @return collection without nulls */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static Collection toCleanedRaw(Collection c) { ArrayList cleaned = new ArrayList(); Iterator iterator = c.iterator(); while (iterator.hasNext()) { Object e = iterator.next(); if (e != null) { cleaned.add(e); } } return cleaned; } }