< prev index next >

src/java.base/share/classes/java/util/stream/Stream.java

Print this page




 915      * collection strategies and composition of collect operations such as
 916      * multiple-level grouping or partitioning.
 917      *
 918      * <p>If the stream is parallel, and the {@code Collector}
 919      * is {@link Collector.Characteristics#CONCURRENT concurrent}, and
 920      * either the stream is unordered or the collector is
 921      * {@link Collector.Characteristics#UNORDERED unordered},
 922      * then a concurrent reduction will be performed (see {@link Collector} for
 923      * details on concurrent reduction.)
 924      *
 925      * <p>This is a <a href="package-summary.html#StreamOps">terminal
 926      * operation</a>.
 927      *
 928      * <p>When executed in parallel, multiple intermediate results may be
 929      * instantiated, populated, and merged so as to maintain isolation of
 930      * mutable data structures.  Therefore, even when executed in parallel
 931      * with non-thread-safe data structures (such as {@code ArrayList}), no
 932      * additional synchronization is needed for a parallel reduction.
 933      *
 934      * @apiNote
 935      * The following will accumulate strings into an ArrayList:
 936      * <pre>{@code
 937      *     List<String> asList = stringStream.collect(Collectors.toList());
 938      * }</pre>
 939      *
 940      * <p>The following will classify {@code Person} objects by city:
 941      * <pre>{@code
 942      *     Map<String, List<Person>> peopleByCity
 943      *         = personStream.collect(Collectors.groupingBy(Person::getCity));
 944      * }</pre>
 945      *
 946      * <p>The following will classify {@code Person} objects by state and city,
 947      * cascading two {@code Collector}s together:
 948      * <pre>{@code
 949      *     Map<String, Map<String, List<Person>>> peopleByStateAndCity
 950      *         = personStream.collect(Collectors.groupingBy(Person::getState,
 951      *                                                      Collectors.groupingBy(Person::getCity)));
 952      * }</pre>
 953      *
 954      * @param <R> the type of the result
 955      * @param <A> the intermediate accumulation type of the {@code Collector}




 915      * collection strategies and composition of collect operations such as
 916      * multiple-level grouping or partitioning.
 917      *
 918      * <p>If the stream is parallel, and the {@code Collector}
 919      * is {@link Collector.Characteristics#CONCURRENT concurrent}, and
 920      * either the stream is unordered or the collector is
 921      * {@link Collector.Characteristics#UNORDERED unordered},
 922      * then a concurrent reduction will be performed (see {@link Collector} for
 923      * details on concurrent reduction.)
 924      *
 925      * <p>This is a <a href="package-summary.html#StreamOps">terminal
 926      * operation</a>.
 927      *
 928      * <p>When executed in parallel, multiple intermediate results may be
 929      * instantiated, populated, and merged so as to maintain isolation of
 930      * mutable data structures.  Therefore, even when executed in parallel
 931      * with non-thread-safe data structures (such as {@code ArrayList}), no
 932      * additional synchronization is needed for a parallel reduction.
 933      *
 934      * @apiNote
 935      * The following will accumulate strings into a List:
 936      * <pre>{@code
 937      *     List<String> asList = stringStream.collect(Collectors.toList());
 938      * }</pre>
 939      *
 940      * <p>The following will classify {@code Person} objects by city:
 941      * <pre>{@code
 942      *     Map<String, List<Person>> peopleByCity
 943      *         = personStream.collect(Collectors.groupingBy(Person::getCity));
 944      * }</pre>
 945      *
 946      * <p>The following will classify {@code Person} objects by state and city,
 947      * cascading two {@code Collector}s together:
 948      * <pre>{@code
 949      *     Map<String, Map<String, List<Person>>> peopleByStateAndCity
 950      *         = personStream.collect(Collectors.groupingBy(Person::getState,
 951      *                                                      Collectors.groupingBy(Person::getCity)));
 952      * }</pre>
 953      *
 954      * @param <R> the type of the result
 955      * @param <A> the intermediate accumulation type of the {@code Collector}


< prev index next >