Java Iterable First getFirst(Iterable iterable)

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

Description

Method description

License

Open Source License

Parameter

Parameter Description
iterable a parameter
T a parameter

Declaration

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

Method Source Code

//package com.java2s;

import java.util.Iterator;

public class Main {
    /**//  w ww .j  ava2s  .  c  o  m
     * Method description
     *
     *
     * @param iterable
     * @param <T>
     *
     * @return
     * @since 1.5
     */
    public static <T> T getFirst(Iterable<T> iterable) {
        T result = null;

        if (iterable != null) {
            result = getFirst(iterable.iterator());
        }

        return result;
    }

    /**
     * Method description
     *
     *
     * @param iterator
     * @param <T>
     *
     * @return
     * @since 1.5
     */
    public static <T> T getFirst(Iterator<T> iterator) {
        T result = null;

        if ((iterator != null) && iterator.hasNext()) {
            result = iterator.next();
        }

        return result;
    }
}

Related

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