Java tutorial
//package com.java2s; /* $License$ */ 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; } }