Class Iterables
- java.lang.Object
-
- com.globalmentor.collections.iterables.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 anOptional
describing the first element of this iterable, or an emptyOptional
if the iterable is empty.
-
-
-
Method Detail
-
findFirst
public static <T> java.util.Optional<T> findFirst(@Nonnull java.lang.Iterable<T> iterable)
Returns anOptional
describing the first element of this iterable, or an emptyOptional
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 emptyOptional
if the iterable is empty. - See Also:
- Good way to get *any* value from a Java Set?,
Iterator.next()
,Stream.findFirst()
,Iterators.findNext(Iterator)
-
-