Java Iterable First getFirst(Iterable iterable)

Here you can find the source of getFirst(Iterable iterable)

Description

get First

License

Open Source License

Declaration

public static <T> T getFirst(Iterable<T> iterable) 

Method Source Code

//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

import java.util.Iterator;

public class Main {
    /**//from  w  w  w  .  j a v a 2  s  .  c o m
     * @deprecated Strongly consider if you want the first element or rather only expect
     *       one element. In the latter case, use {@link #getUnique(Iterable)} or 
     *       {@link #getSingleIfExist(Iterable)}.
     */
    public static <T> T getFirst(Iterable<T> iterable) {
        return getFirst(iterable, null);
    }

    public static <T> T getFirst(Iterable<? extends T> iterable, T def) {
        final Iterator<? extends T> iter = iterable.iterator();
        return iter.hasNext() ? iter.next() : def;
    }
}

Related

  1. getFirst(final Iterable iterable)
  2. getFirst(Iterable iterable)
  3. getFirst(Iterable c)
  4. getFirst(Iterable iterable)
  5. getFirst(Iterable iterable)
  6. getFirst(Iterable iterable, T defaultValue)
  7. getFirstElement(Object maybeIterable)
  8. getFirstOrNull(Iterable it)
  9. getFirstOrNull(Iterable iterable)