Java Utililty Methods Collection First

List of utility methods to do Collection First

Description

The list of methods to do Collection First are organized into topic(s).

Method

Tfirst(Collection c)
first
return c.iterator().next();
Tfirst(Collection collection)
Return the first element of the collection.
if (collection.isEmpty()) {
    return null;
return collection.iterator().next();
Tfirst(Collection collection)
Replaces first() LINQ Returns first object of collection or null if empty
Iterator<T> iterator = collection.iterator();
if (iterator.hasNext())
    return iterator.next();
else
    return null;
ObjectfirstElement(Collection in)
return the first element in a collection - this is most useful where only one item exists in the collection
if (in.size() == 0)
    throw new IllegalArgumentException("firstElement requies at least one entry");
return (in.iterator().next());
TfirstElement(Collection c)
first Element
if (c != null && !c.isEmpty()) {
    return c.iterator().next();
return null;
TfirstElementOf(final Collection collection)
Returns the first element of the given collection
if (isEmpty(collection)) {
    return null;
return collection.iterator().next();
TfirstElementOf(final Collection items)
first Element Of
if (items != null && !items.isEmpty()) {
    return items.iterator().next();
return null;
ObjectfirstFrom(Collection collection)
first From
return collection.iterator().next();
TfirstFrom(Collection coll)
first From
if (isEmpty(coll))
    return null;
return coll.iterator().next();
CollectionfirstNonEmpty(Collection... collections)
first Non Empty
for (Collection<T> collection : collections)
    if (!isEmpty(collection))
        return collection;
return emptySet();