android/guava/src/com/google/common/collect/Iterables.java
@NullableDecl
  public static <T> T getOnlyElement(Iterable<? extends T> iterable, @NullableDecl T defaultValue) {
    return Iterators.getOnlyElement(iterable.iterator(), defaultValue);
  }
@NullableDecl
  public static <T> T getOnlyElement(Iterable<? extends T> iterable, @NullableDecl T defaultValue) {
    return Iterators.getOnlyElement(iterable.iterator(), defaultValue);
  }
@ NullableDecl public static < T > T getOnlyElement ( Iterable < ? extends T > iterable , @ NullableDecl T defaultValue ) { return Iterators . getOnlyElement ( iterable . iterator ( ) , defaultValue ) ; }
Returns the single element contained in {@code iterable}, or {@code defaultValue} if the
iterable is empty.

<p><b>Java 8 users:</b> the {@code Stream} equivalent to this method is {@code
stream.collect(MoreCollectors.toOptional()).orElse(defaultValue)}.

@throws IllegalArgumentException if the iterator contains multiple elements
Returns the single element contained in { @code iterable } or { @code defaultValue } if the iterable is empty .