find Preceding Item in a List - Java java.util

Java examples for java.util:List Search

Description

find Preceding Item in a List

Demo Code


//package com.java2s;
import java.util.List;

public class Main {
    public static <E> E findPrecedingItem(final List<E> list, final E item) {
        E lastSeenItem = null;//www.j  a  va  2 s.  c  o m

        for (E x : list) {
            if (x == item) {
                return lastSeenItem;
            }

            lastSeenItem = x;
        }

        return null;
    }
}

Related Tutorials