android/guava/src/com/google/common/collect/Iterables.java
@NullableDecl
  public static <T> T getFirst(Iterable<? extends T> iterable, @NullableDecl T defaultValue) {
    return Iterators.getNext(iterable.iterator(), defaultValue);
  }
@NullableDecl
  public static <T> T getFirst(Iterable<? extends T> iterable, @NullableDecl T defaultValue) {
    return Iterators.getNext(iterable.iterator(), defaultValue);
  }
Returns the first element in {@code iterable} or {@code defaultValue} if the iterable is empty.
The {@link Iterators} analog to this method is {@link Iterators#getNext}.

<p>If no default value is desired (and the caller instead wants a {@link
NoSuchElementException} to be thrown), it is recommended that {@code
iterable.iterator().next()} is used instead.

<p>To get the only element in a single-element {@code Iterable}, consider using {@link
#getOnlyElement(Iterable)} or {@link #getOnlyElement(Iterable, Object)} instead.

<p><b>{@code Stream} equivalent:</b> {@code stream.findFirst().orElse(defaultValue)}

@param defaultValue the default value to return if the iterable is empty
@return the first element of {@code iterable} or the default value
@since 7.0