Jdk8-java Streams Collector

Source: Internet
Author: User

CollectorsThe class contains many common aggregation operations, such as accumulating into a collection, string concatenation, shrinking, and other summary calculations, and creating a summary table (through groupingBy() ).

Built-in collectors
Collecting Device Behavior
toList() Collects elements into one List .
toSet() Collects elements into one Set .
toCollection(Supplier<Collection>) Collects elements into a specific type Collection .
toMap(Function<T, K>, Function<T, V>) The elements are collected into one Map , and the elements are converted to key values according to the mapping function provided.
summingInt(ToIntFunction<T>) Calculates the sum of the int results that are applied to each element (and to the version) of the provided value mapping function long double .
summarizingInt(ToIntFunction<T>) Calculates the,,,,,,,, int long double sum min max ,, count and average .
reducing() Apply a reduction to an element (typically used as a downstream collector, for example groupingBy ) (various versions).
partitioningBy(Predicate<T>) The elements are divided into two groups: the expected groups that are provided for them are retained and the expected groups are not retained.
partitioningBy(Predicate<T>, Collector) Partitions an element, using the specified downstream collector to process each partition.
groupingBy(Function<T,U>) Groups elements into one Map , where the key is the provided function applied to the flow element, and the value is the list of elements that share the key.
groupingBy(Function<T,U>, Collector) Groups the elements, using the specified downstream collector to handle the values associated with each group.
minBy(BinaryOperator<T>) Calculates the minimum value of the element (same as the maxBy() same).
mapping(Function<T,U>, Collector) Applies the provided mapping function to each element and processes it using the specified downstream collector (typically used as the downstream collector itself, for example groupingBy ).
joining() Assuming that the elements are String types, the elements are joined to a string (perhaps using separators, prefixes, and suffixes).
counting() Calculates the number of elements. (typically used as a downstream collector.) )

Jdk8-java Streams Collector

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.