Java ListIterator Usage getLastNonNull(List l)

Here you can find the source of getLastNonNull(List l)

Description

Returns the last non-null element in the given list; or, if there is no non-null element, it returns null.

License

Open Source License

Parameter

Parameter Description
l The list. It may be null, in which case null is returned.

Return

The element.

Declaration


public static <E> E getLastNonNull(List<E> l) 

Method Source Code


//package com.java2s;
/* $License$ */// w w w  .  j a v a2  s.  com

import java.util.List;
import java.util.ListIterator;

public class Main {
    /**
     * Returns the last non-null element in the given list; or, if
     * there is no non-null element, it returns null.
     *
     * @param l The list. It may be null, in which case null is
     * returned.
     *
     * @return The element.
     */

    public static <E> E getLastNonNull(List<E> l) {
        if (l == null) {
            return null;
        }
        ListIterator<E> i = l.listIterator(l.size());
        while (i.hasPrevious()) {
            E e = i.previous();
            if (e != null) {
                return e;
            }
        }
        return null;
    }
}

Related

  1. findObject(Object item, ListIterator iter)
  2. findPrevious(ListIterator iter)
  3. getAll_SequentialAccess( List idxs, List values)
  4. getCamelNameSegments(String camelName)
  5. getCurrentElement(ListIterator listIterator)
  6. goToFirst(ListIterator iterator)
  7. gotoIndex(ListIterator iterator, int index)
  8. incrementalComponentWiseAverageArbitraryDepth(Object average, int n, Object newItems)
  9. indexOf(List list, E object)