Java Iterable First getFirstOrNull(Iterable it)

Here you can find the source of getFirstOrNull(Iterable it)

Description

get First Or Null

License

Open Source License

Declaration

public static <T> T getFirstOrNull(Iterable<T> it) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Iterator;
import java.util.NoSuchElementException;

public class Main {
    public static <T> T getFirstOrNull(Iterable<T> it) {
        if (it == null)
            return null;
        Iterator<T> i = it.iterator();
        if (i == null || !i.hasNext())
            return null;
        try {/*w w  w.  java  2 s  . co  m*/
            return i.next();
        } catch (NoSuchElementException e) {
            return null;
        }
    }
}

Related

  1. getFirst(Iterable iterable)
  2. getFirst(Iterable iterable)
  3. getFirst(Iterable iterable)
  4. getFirst(Iterable iterable, T defaultValue)
  5. getFirstElement(Object maybeIterable)
  6. getFirstOrNull(Iterable iterable)
  7. removeFirst(Iterable iterable)