MCPcopy
hub / github.com/google/guava / first

Method first

guava/src/com/google/common/collect/FluentIterable.java:512–516  ·  view source on GitHub ↗

Returns an {@link Optional} containing the first element in this fluent iterable. If the iterable is empty, {@code Optional.absent()} is returned. <p><b>{@code Stream} equivalent:</b> if the goal is to obtain any element, {@link Stream#findAny}; if it must specifically be the <i>first</i> element,

()

Source from the content-addressed store, hash-verified

510 * iterator().next()} or {@link Iterables#getFirst} instead.
511 */
512 @SuppressWarnings("nullness") // Unsafe, but we can't do much about it now.
513 public final Optional<@NonNull E> first() {
514 Iterator<E> iterator = getDelegate().iterator();
515 return iterator.hasNext() ? Optional.of(iterator.next()) : Optional.absent();
516 }
517
518 /**
519 * Returns an {@link Optional} containing the last element in this fluent iterable. If the

Callers

nothing calls this directly

Calls 6

getDelegateMethod · 0.95
ofMethod · 0.95
absentMethod · 0.95
iteratorMethod · 0.65
nextMethod · 0.65
hasNextMethod · 0.45

Tested by

no test coverage detected