Java Iterable First getFirst(final Iterable iterable)

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

Description

get First

License

Open Source License

Declaration

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

Method Source Code


//package com.java2s;
/*/*  ww w.ja  v  a 2 s  .co m*/
 * Copyright (c) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
 */

import java.util.Iterator;

public class Main {
    public static <T> T getFirst(final Iterable<T> iterable) {
        if (iterable == null) {
            return null;
        }

        final Iterator<T> iterator = iterable.iterator();
        if (iterator == null) {
            return null;
        }

        return iterator.hasNext() ? iterator.next() : null;
    }
}

Related

  1. firstElement(Iterable iterable)
  2. firstElementOrNull(Iterable iterable)
  3. firstOf(final Iterable iterable)
  4. firstOrNull(Iterable iterable)
  5. getFirst(final Iterable iterable)
  6. getFirst(Iterable iterable)
  7. getFirst(Iterable c)
  8. getFirst(Iterable iterable)
  9. getFirst(Iterable iterable)