Java List Tail tail(List l)

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

Description

Returns the tail of the provided List i.e. the sublist which contains all elements of the given list except the #head(List) head .

License

Open Source License

Parameter

Parameter Description
l the list whose tail is sought.
T the type of the List.

Exception

Parameter Description
NullPointerException if l is null
UnsupportedOperationException if the provided list was empty.

Return

the tail sublist, which will be an empty list if the provided list had only a single element.

Declaration

public static <T> List<T> tail(List<T> l) 

Method Source Code

//package com.java2s;
/*/*from   w w w.ja v a2 s  . c o  m*/
 * Copyright (C) 2005-2015 Alfresco Software Limited.
 *
 * This file is part of Alfresco
 *
 * Alfresco is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Alfresco is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.List;

public class Main {
    /**
     * Returns the tail of the provided List i&#46;e&#46; the sublist which contains
     * all elements of the given list except the {@link #head(List) head}.
     *
     * @param l the list whose tail is sought.
     * @param <T> the type of the List.
     * @return the tail sublist, which will be an empty list if the provided list had only a single element.
     * @throws NullPointerException if l is {@code null}
     * @throws UnsupportedOperationException if the provided list was empty.
     */
    public static <T> List<T> tail(List<T> l) {
        if (l.isEmpty()) {
            throw new UnsupportedOperationException(
                    "Cannot get tail of empty list.");
        } else {
            return l.subList(1, l.size());
        }
    }
}

Related

  1. tail(final List list)
  2. tail(List list)
  3. tail(List list, int tailLength)
  4. tail(List lines, int number)
  5. tail(List lst, int from)
  6. tail(List list)
  7. tail(List list)
  8. tail(List list)
  9. tail(List list)