Class Iterables


  • public class Iterables
    extends java.lang.Object
    Various utilities to be used with iterables.
    Author:
    Garret Wilson
    See Also:
    Iterable
    • Constructor Summary

      Constructors 
      Constructor Description
      Iterables()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.util.Optional<T> findFirst​(java.lang.Iterable<T> iterable)
      Returns an Optional describing the first element of this iterable, or an empty Optional if the iterable is empty.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Iterables

        public Iterables()
    • Method Detail

      • findFirst

        public static <T> java.util.Optional<T> findFirst​(@Nonnull
                                                          java.lang.Iterable<T> iterable)
        Returns an Optional describing the first element of this iterable, or an empty Optional if the iterable is empty.
        Implementation Specification:
        This implementation efficiently short-circuits creating an iterator if the iterable is an instance of a Collection, which has a known size.
        Type Parameters:
        T - the type of elements returned by the iterator.
        Parameters:
        iterable - The iterable from which the first object should be retrieved.
        Returns:
        An Optional describing the first element of this iterable, or an empty Optional if the iterable is empty.
        See Also:
        Good way to get *any* value from a Java Set?, Iterator.next(), Stream.findFirst(), Iterators.findNext(Iterator)