Java Utililty Methods Collection Null

List of utility methods to do Collection Null

Description

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

Method

FremoveNulls(F collection)
remove Nulls
Iterator<E> iterator = collection.iterator();
while (iterator.hasNext()) {
    if (iterator.next() == null) {
        iterator.remove();
return collection;
voidremoveNulls(final Collection collection)
remove Nulls
for (final Iterator<?> iter = collection.iterator(); iter.hasNext();) {
    if (iter.next() == null) {
        iter.remove();
ListsortNumbers(Collection values, boolean removeNull)
Utility method which takes a Collection of Numbers, and returns this back as a List, in order of each Number's double value If removeNull is true, null values will be ignored and not returned If removeNull is false, null values will be sorted to the end of the list
List<T> valueList = new ArrayList<T>(values);
if (removeNull) {
    values.remove(null);
Collections.sort(valueList, new Comparator<T>() {
    public int compare(T n1, T n2) {
        if (n1 == null) {
            return n2 == null ? 0 : 1;
...
voidstripNulls(T collection)
strip Nulls
Iterator<?> iterator = collection.iterator();
while (iterator.hasNext()) {
    if (iterator.next() == null)
        iterator.remove();
TtrimToNull(T collection)
trim To Null
return isEmpty(collection) ? null : collection;