Here you can find the source of tail(List
Parameter | Description |
---|---|
l | the list whose tail is sought. |
T | the type of the List. |
Parameter | Description |
---|---|
NullPointerException | if l is null |
UnsupportedOperationException | if the provided list was empty. |
public static <T> List<T> tail(List<T> l)
//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.e. 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()); } } }