Returns the single element contained in {@code iterable}. <p><b>Java 8+ users:</b> the {@code Stream} equivalent to this method is {@code stream.collect(MoreCollectors.onlyElement())}. @throws NoSuchElementException if the iterable is empty @throws IllegalArgumentException if the iterable contains
(Iterable<T> iterable)
| 259 | * @throws IllegalArgumentException if the iterable contains multiple elements |
| 260 | */ |
| 261 | @ParametricNullness |
| 262 | public static <T extends @Nullable Object> T getOnlyElement(Iterable<T> iterable) { |
| 263 | return Iterators.getOnlyElement(iterable.iterator()); |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Returns the single element contained in {@code iterable}, or {@code defaultValue} if the |