Java Collection First nullSafeFirstElement(Collection collection)

Here you can find the source of nullSafeFirstElement(Collection collection)

Description

null Safe First Element

License

Open Source License

Declaration

public static <T> T nullSafeFirstElement(Collection<T> collection) 

Method Source Code

//package com.java2s;
/**//from w  w w. jav a  2s  . c  o m
 * Copyright 2008 Autentia Real Business Solutions S.L. This file is part of autentia-util. autentia-util 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, version 3 of the License. autentia-util 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 autentia-util. If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Collection;

public class Main {

    public static <T> T nullSafeFirstElement(Collection<T> collection) {
        try {
            return collection.iterator().next();
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. getFirstNotNullValue(final Collection collection)
  2. getFirstOrNull(final Collection collection)
  3. getFirstSortedItem( Collection items, T defaultValue)
  4. getUnionSize(Collection firstCollection, Collection secondCollection)
  5. intersect(Collection firstSet, Collection secondSet)
  6. removeFirst(Collection collection, int numToRemove)
  7. removeFirst(Collection c)
  8. sub(Collection coll, int first, int size)
  9. subtract(Collection firstCollection, Collection secondCollection)