Class Collectors


  • public final class Collectors
    extends Object
    • Method Detail

      • toMap

        public static <T,​K> Collector<T,​?,​Map<K,​T>> toMap​(Function<? super T,​? extends K> keyMapper)
      • toLinkedMap

        public static <T,​K> Collector<T,​?,​Map<K,​T>> toLinkedMap​(Function<? super T,​? extends K> keyMapper)
      • toLinkedSet

        public static <T> Collector<T,​?,​Set<T>> toLinkedSet()
      • forEachBatch

        public static <T> Collector<T,​?,​Void> forEachBatch​(Consumer<List<T>> batchConsumer,
                                                                       int batchSize)
      • reversedStream

        public static <T> Collector<T,​?,​Stream<T>> reversedStream()
        Returns a collector which takes the elements of the current stream and returns a new stream with the same elements in reverse order.

        This collector will collect all elements from a stream into memory in order to return the reversed stream. As a result this collector may not be suitable for extremely large or infinite streams.

        Type Parameters:
        T - The type of the elements
        Returns:
        A Collector that returns the elements of a stream in reverse order.
      • findLast

        public static <T> Collector<T,​?,​Optional<T>> findLast()
        Returns a collector which will return the last element of a stream, if present.
        Type Parameters:
        T - The type of the elements
        Returns:
        An Optional containing the last element of the stream or Optional.empty() if the stream is empty.