Returns an Optional containing the first element in this fluent iterable. If the iterable is empty, Optional.absent() is returned. Stream equivalent: if the goal is to obtain any element, stream.findAny(); if it must specifically be the first element
()
| 487 | * {@code iterator().next()} or {@link Iterables#getFirst} instead. |
| 488 | */ |
| 489 | public final Optional<E> first() { |
| 490 | Iterator<E> iterator = iterable.iterator(); |
| 491 | return iterator.hasNext() ? Optional.of(iterator.next()) : Optional.<E>absent(); |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * Returns an {@link Optional} containing the last element in this fluent iterable. If the |