android/guava/src/com/google/common/collect/Iterables.java
public static <T> T getLast(Iterable<T> iterable) {
    // TODO(kevinb): Support a concurrently modified collection?
    if (iterable instanceof List) {
      List<T> list = (List<T>) iterable;
      if (list.isEmpty()) {
        throw new NoSuchElementException();
      }
      return getLastInNonemptyList(list);
    }

    return Iterators.getLast(iterable.iterator());
  }
public static <T> T getLast(Iterable<T> iterable) {
    // TODO(kevinb): Support a concurrently modified collection?
    if (iterable instanceof List) {
      List<T> list = (List<T>) iterable;
      if (list.isEmpty()) {
        throw new NoSuchElementException();
      }
      return getLastInNonemptyList(list);
    }

    return Iterators.getLast(iterable.iterator());
  }
Returns the last element of {@code iterable}. If {@code iterable} is a {@link List} with {@link
RandomAccess} support, then this operation is guaranteed to be {@code O(1)}.

<p><b>{@code Stream} equivalent:</b> {@link Streams#findLast Streams.findLast(stream).get()}

@return the last element of {@code iterable}
@throws NoSuchElementException if the iterable is empty