Skip to content

Instantly share code, notes, and snippets.

@overpas
overpas / ElementCollectors.java
Last active October 14, 2020 12:39
Java Streams API Elements Collectors
public final class ElementCollectors {
private static final String MESSAGE_SINGLE_MANY_ITEMS = "More than one items";
private ElementCollectors() {
// utils
}
public static <T> Collector<T, ?, T> single(String errorMessage) {
return single(Collectors.toList(), errorMessage);