Java List First Item removeFirstElement(List l)

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

Description

Removes and returns the element at index 0, or null if the List is empty.

License

Apache License

Parameter

Parameter Description
l the List object to process

Return

the first element that was in the list, but has now been removed.

Declaration

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

Method Source Code

//package com.java2s;
/*//from www . j  av  a2s  .  co  m
Copyright 1996-2010 Ariba, Inc.
    
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    
$Id: //ariba/platform/util/core/ariba/util/core/ListUtil.java#38 $
*/

import java.util.List;

public class Main {
    /**
    Removes and returns the element at index 0, or <b>null</b> if the
    List is empty.
    @param l the List object to process
    @return the first element that was in the list, but has now
    been removed.
    @aribaapi documented
    */
    public static <T> T removeFirstElement(List<T> l) {
        if (l.isEmpty()) {
            return null;
        }

        return l.remove(0);
    }
}

Related

  1. prepend(String first, List list)
  2. putFirstLast(List list)
  3. removeFirst(final List list)
  4. removeFirst(List list)
  5. removeFirst(List list)
  6. removeFirstHalfElements(final List list)
  7. replace(int codePoint, int firstCharacterInGroup, List referenceList)
  8. swap(List list, int firstIndex, int secondIndex)