Java List First Item getFirstOrNull(List list)

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

Description

Return the first element of list.

License

Open Source License

Parameter

Parameter Description
T Any type
list The List

Return

list[0] or null if list == null || list.isEmpty

Declaration

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

Method Source Code

//package com.java2s;
/*/*from  www . j  ava  2s  .co  m*/
 * openwms.org, the Open Warehouse Management System.
 * Copyright (C) 2014 Heiko Scherrer
 *
 * This file is part of openwms.org.
 *
 * openwms.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as 
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * openwms.org 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this software. If not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

import java.util.List;

public class Main {
    /**
     * Return the first element of list. If list is <code>null</code> of empty, <code>null</code> is returned.
     * 
     * @param <T>
     *            Any type
     * @param list
     *            The {@link List}
     * @return list[0] or <code>null</code> if list == null || list.isEmpty
     */
    public static <T> T getFirstOrNull(List<T> list) {
        if (list == null || list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }
}

Related

  1. getFirstNameIndex(List list)
  2. getFirstNonEmptyIndex(final List> list)
  3. getFirstObject(List valueList)
  4. getFirstOccurNic(List nics, String line)
  5. getFirstOrNull(List elements)
  6. getFirstRowMatch(List list, int columnIndex, T value)
  7. getFirstRowResults(List> llo, String reason)
  8. getFirstString(Object list)
  9. getFirstValueString(List values)

    HOME | Copyright © www.java2s.com 2016