Java List First Item getFirst(List list)

Here you can find the source of getFirst(List list)

Description

Returns the first element in a list, or null if there is none.

License

Mozilla Public License

Parameter

Parameter Description
list A list.

Return

The first list element, or null if none.

Declaration

public static <T> T getFirst(List<T> list) 

Method Source Code

//package com.java2s;
/**/*from  w w w.  j  a  v  a  2 s  . c o m*/
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
 * If a copy of the MPL was not distributed with this file, You can obtain one at
 * http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is also subject to the terms of the Health-Related Additional
 * Disclaimer of Warranty and Limitation of Liability available at
 * http://www.carewebframework.org/licensing/disclaimer.
 */

import java.util.List;

public class Main {
    /**
     * Returns the first element in a list, or null if there is none.
     * 
     * @param list A list.
     * @return The first list element, or null if none.
     */
    public static <T> T getFirst(List<T> list) {
        return list == null || list.isEmpty() ? null : list.get(0);
    }
}

Related

  1. getAllButFirst(List list)
  2. getDependenciesPrivate(List projects, boolean firstDependencies)
  3. getFirst(List c)
  4. getFirst(List l)
  5. getFirst(List list)
  6. getFirst(List source)
  7. getFirstAsString(Map> multiValueMap, String key)
  8. getFirstColumn(List> llo, String reason)
  9. getFirstDuplicateValue(List values)