Java Utililty Methods Iterable First

List of utility methods to do Iterable First

Description

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

Method

TfirstOrNull(Iterable iterable)
first Or Null
return firstOrNull(iterable.iterator());
TgetFirst(final Iterable iterable)
Gets the first element from an iterable.
if (iterable == null) {
    return null;
final Iterator<? extends T> iterator = iterable.iterator();
if (iterator.hasNext()) {
    return iterator.next();
} else {
    return null;
...
TgetFirst(final Iterable iterable)
get First
if (iterable == null) {
    return null;
final Iterator<T> iterator = iterable.iterator();
if (iterator == null) {
    return null;
return iterator.hasNext() ? iterator.next() : null;
...
TgetFirst(Iterable iterable)
Return the first element in the given (non-empty) Iterable
if (iterable instanceof List) {
    final List<T> list = (List<T>) iterable;
    if (list.isEmpty())
        throw new NoSuchElementException();
    return list.get(0);
} else {
    return iterable.iterator().next();
ObjectgetFirst(Iterable c)
get First
final Iterator<T> it = c.iterator();
if (!it.hasNext()) {
    return null;
} else {
    return it.next();
TgetFirst(Iterable iterable)
Method description
T result = null;
if (iterable != null) {
    result = getFirst(iterable.iterator());
return result;
TgetFirst(Iterable iterable)
Returns the first element from the given Iterable .
try {
    if (iterable != null) {
        Iterator<T> iter = iterable.iterator();
        return iter.next();
    } else {
        return null;
} catch (NoSuchElementException e) {
...
TgetFirst(Iterable iterable)
get First
return getFirst(iterable, null);
TgetFirst(Iterable iterable, T defaultValue)
get First
Iterator<T> iterator = iterable.iterator();
return iterator.hasNext() ? iterator.next() : defaultValue;
ObjectgetFirstElement(Object maybeIterable)
Returns the first element, if any, of an object that may be an Iterable
if (!(maybeIterable instanceof Iterable<?>))
    return null;
Iterable<?> iterable = (Iterable<?>) maybeIterable;
Iterator<?> iterator = iterable.iterator();
return iterator.hasNext() ? iterator.next() : null;