@Beta @GwtCompatible public final class MoreCollectors extends Object
java.util.stream.Collectors
that are not otherwise associated
with a com.google.common
type.Modifier and Type | Method and Description |
---|---|
static <T> Collector<T,?,T> |
onlyElement()
A collector that takes a stream containing exactly one element and returns that element.
|
static <T> Collector<T,?,Optional<T>> |
toOptional()
A collector that converts a stream of zero or one elements to an
Optional . |
public static <T> Collector<T,?,Optional<T>> toOptional()
Optional
. The returned
collector throws an IllegalArgumentException
if the stream consists of two or more
elements, and a NullPointerException
if the stream consists of exactly one element,
which is null.public static <T> Collector<T,?,T> onlyElement()
IllegalArgumentException
if the stream consists of two or
more elements, and a NoSuchElementException
if the stream is empty.Copyright © 2010–2018. All rights reserved.