Here you can find the source of getLastNonNull(List
Parameter | Description |
---|---|
l | The list. It may be null, in which case null is returned. |
public static <E> E getLastNonNull(List<E> l)
//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; } }