Java ListIterator Usage trimTail(List l)

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

Description

Remove all null elements at the end of the list.

License

Open Source License

Declaration

public static <T> void trimTail(List<T> l) 

Method Source Code

//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

import java.util.Collection;

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

public class Main {
    /**//from   w ww .j av  a  2  s .c om
     * Remove all null elements at the end of the list.
     */
    public static <T> void trimTail(List<T> l) {
        final ListIterator<T> it = l.listIterator(l.size());
        while (it.hasPrevious()) {
            if (it.previous() != null)
                return;
            it.remove();
        }
    }

    /**
     * @param coll
     * @postcondition (coll == null) --> (result == 0)
     * @postcondition (coll != null) --> (result == coll.size())
     */
    public static int size(Collection<?> coll) {
        return (coll == null) ? 0 : coll.size();
    }
}

Related

  1. toInt(final List digits, final int base)
  2. toIntegerArray(List list)
  3. toLowerCase(List list)
  4. toLowerCase(List stringList)
  5. toposort(Iterable items, Comparator partOrder)
  6. valueOf(E... elements)
  7. walkTo(String target, String path, int offset)