Class Collectors2

java.lang.Object
org.eclipse.collections.impl.collector.Collectors2

public final class Collectors2
extends Object

A set of Collectors for Eclipse Collections types and algorithms.

Includes converter Collectors to{Immutable}{Sorted}{List/Set/Bag/Map/BiMap/Multimap}.
Includes Collectors for select, reject, partition.
Includes Collectors for collect, collect{Boolean/Byte/Char/Short/Int/Float/Long/Double}.
Includes Collectors for makeString, zip, chunk.
Includes Collectors for sumBy{Int/Float/Long/Double}.

Use these Collectors with @RichIterable.reduceInPlace(Collector) and @Stream.collect(Collector).

Since:
8.0
  • Method Details

    • makeString

      public static <T> Collector<T,​?,​String> makeString()

      Returns a String composed of elements separated by ", ".

      Examples:

      System.out.println(Interval.oneTo(5).stream().collect(Collectors2.makeString()));
      System.out.println(Interval.oneTo(5).reduceInPlace(Collectors2.makeString()));

      Prints:

       1, 2, 3, 4, 5
       1, 2, 3, 4, 5
       

      Equivalent to using @RichIterable.makeString()

      System.out.println(Interval.oneTo(5).makeString());
    • makeString

      public static <T> Collector<T,​?,​String> makeString​(CharSequence separator)

      Returns a String composed of elements separated by the specified separator.

      Examples:

      System.out.println(Interval.oneTo(5).stream().collect(Collectors2.makeString("")));
      System.out.println(Interval.oneTo(5).reduceInPlace(Collectors2.makeString("")));

      Prints:

       12345
       12345
       

      Equivalent to using @RichIterable.makeString(String)

      System.out.println(Interval.oneTo(5).makeString(""));
    • makeString

      public static <T> Collector<T,​?,​String> makeString​(CharSequence start, CharSequence separator, CharSequence end)

      Returns a String composed of elements separated by the specified separator and beginning with start String and ending with end String.

      Examples:

      System.out.println(Interval.oneTo(5).stream().collect(Collectors2.makeString("[", ":", "]")));
      System.out.println(Interval.oneTo(5).reduceInPlace(Collectors2.makeString("[", ":", "]")));

      Prints:

       [1:2:3:4:5]
       [1:2:3:4:5]
       

      Equivalent to using @RichIterable.makeString(String, String, String)}

      System.out.println(Interval.oneTo(5).makeString("[", ":", "]"));
    • toList

      public static <T> Collector<T,​?,​MutableList<T>> toList()

      Returns the elements as a MutableList.

      Examples:

      MutableList<Integer> numbers1 = Interval.oneTo(5).stream().collect(Collectors2.toList());
      MutableList<Integer> numbers2 = Interval.oneTo(5).reduceInPlace(Collectors2.toList());

      Equivalent to using @RichIterable.toList()}

      MutableList<Integer> numbers = Interval.oneTo(5).toList();
    • toImmutableList

      public static <T> Collector<T,​?,​ImmutableList<T>> toImmutableList()

      Returns the elements as an ImmutableList.

      Examples:

      ImmutableList<Integer> numbers1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableList());
      ImmutableList<Integer> numbers2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableList());

      Equivalent to using @RichIterable.toList() followed by: @MutableList.toImmutable().

      ImmutableList<Integer> numbers = Interval.oneTo(5).toList().toImmutable();
    • toSet

      public static <T> Collector<T,​?,​MutableSet<T>> toSet()

      Returns the elements as a MutableSet.

      Examples:

      MutableSet<Integer> set1 = Interval.oneTo(5).stream().collect(Collectors2.toSet());
      MutableSet<Integer> set2 =Interval.oneTo(5).reduceInPlace(Collectors2.toSet());

      Equivalent to using @RichIterable.toSet()}

      MutableSet<Integer> set = Interval.oneTo(5).toSet();
    • toImmutableSet

      public static <T> Collector<T,​?,​ImmutableSet<T>> toImmutableSet()

      Returns the elements as an ImmutableSet.

      Examples:

      ImmutableSet<Integer> set1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableSet());
      ImmutableSet<Integer> set2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableSet());

      Equivalent to using @RichIterable.toSet() followed by: @MutableSet.toImmutable().

      ImmutableSet<Integer> set = Interval.oneTo(5).toSet().toImmutable();
    • toSortedSet

      public static <T> Collector<T,​?,​MutableSortedSet<T>> toSortedSet()

      Returns the elements as a MutableSortedSet.

      Examples:

      MutableSortedSet<Integer> set1 = Interval.oneTo(5).stream().collect(Collectors2.toSortedSet());
      MutableSortedSet<Integer> set2 = Interval.oneTo(5).reduceInPlace(Collectors2.toSortedSet());

      Equivalent to using @RichIterable.toSortedSet()}.

      MutableSortedSet<Integer> set = Interval.oneTo(5).toSortedSet();
    • toImmutableSortedSet

      public static <T> Collector<T,​?,​ImmutableSortedSet<T>> toImmutableSortedSet()

      Returns the elements as an ImmutableSortedSet.

      Examples:

      ImmutableSortedSet<Integer> set1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableSortedSet());
      ImmutableSortedSet<Integer> set2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableSortedSet());

      Equivalent to using @RichIterable.toSortedSet() followed by: @MutableSortedSet.toImmutable().

      ImmutableSortedSet<Integer> set = Interval.oneTo(5).toSortedSet().toImmutable();
    • toSortedSet

      public static <T> Collector<T,​?,​MutableSortedSet<T>> toSortedSet​(Comparator<? super T> comparator)

      Returns the elements as a MutableSortedSet using the specified comparator.

      Examples:

      MutableSortedSet<Integer> set1 = Interval.oneTo(5).stream().collect(Collectors2.toSortedSet(Comparator.naturalOrder()));
      MutableSortedSet<Integer> set2 = Interval.oneTo(5).reduceInPlace(Collectors2.toSortedSet(Comparator.naturalOrder()));

      Equivalent to using @RichIterable.toSortedSet(Comparator).

      MutableSortedSet<Integer> set = Interval.oneTo(5).toSortedSet(Comparator.naturalOrder());
    • toSortedSetBy

      public static <T,​ V extends Comparable<? super V>> Collector<T,​?,​MutableSortedSet<T>> toSortedSetBy​(Function<? super T,​? extends V> function)

      Returns the elements as a MutableSortedSet using the specified function to compare each element.

      Examples:

      MutableSortedSet<Integer> set1 = Interval.oneTo(5).stream().collect(Collectors2.toSortedSetBy(Object::toString));
      MutableSortedSet<Integer> set2 = Interval.oneTo(5).reduceInPlace(Collectors2.toSortedSetBy(Object::toString));

      Equivalent to using @RichIterable.toSortedSetBy(Function).

      MutableSortedSet<Integer> set = Interval.oneTo(5).toSortedSetBy(Object::toString);
    • toImmutableSortedSet

      public static <T> Collector<T,​?,​ImmutableSortedSet<T>> toImmutableSortedSet​(Comparator<? super T> comparator)

      Returns the elements as an ImmutableSortedSet using the specified comparator.

      Examples:

      ImmutableSortedSet<Integer> set1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableSortedSet(Comparator.naturalOrder()));
      ImmutableSortedSet<Integer> set2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableSortedSet(Comparator.naturalOrder()));

      Equivalent to using @RichIterable.toSortedSet(Comparator) followed by: @MutableSortedSet.toImmutable().

      ImmutableSortedSet<Integer> set = Interval.oneTo(5).toSortedSet(Comparator.naturalOrder()).toImmutable();
    • toBag

      public static <T> Collector<T,​?,​MutableBag<T>> toBag()

      Returns the elements as a MutableBag.

      Examples:

      MutableBag<Integer> bag1 = Interval.oneTo(5).stream().collect(Collectors2.toBag());
      MutableBag<Integer> bag2 = Interval.oneTo(5).reduceInPlace(Collectors2.toBag());

      Equivalent to using @RichIterable.toBag()}

      MutableBag<Integer> bag = Interval.oneTo(5).toBag();
    • toImmutableBag

      public static <T> Collector<T,​?,​ImmutableBag<T>> toImmutableBag()

      Returns the elements as an ImmutableBag.

      Examples:

      ImmutableBag<Integer> bag1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableBag());
      ImmutableBag<Integer> bag2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableBag());

      Equivalent to using @RichIterable.toBag() followed by: @MutableBag.toImmutable().

      ImmutableBag<Integer> bag = Interval.oneTo(5).toBag().toImmutable();
    • toSortedList

      public static <T> Collector<T,​?,​MutableList<T>> toSortedList()

      Returns the elements as a MutableList that has been sorted.

      Examples:

      MutableList<Integer> list1 = Interval.oneTo(5).stream().collect(Collectors2.toSortedList());
      MutableList<Integer> list2 = Interval.oneTo(5).reduceInPlace(Collectors2.toSortedList());

      Equivalent to using @RichIterable.toSortedList()}

      MutableList<Integer> list = Interval.oneTo(5).toSortedList();
    • toImmutableSortedList

      public static <T> Collector<T,​?,​ImmutableList<T>> toImmutableSortedList()

      Returns the elements as an ImmutableList that has been sorted.

      Examples:

      ImmutableList<Integer> list1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableSortedList());
      ImmutableList<Integer> list2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableSortedList());

      Equivalent to using @RichIterable.toSortedList() followed by: @MutableList.toImmutable().

      ImmutableList<Integer> list = Interval.oneTo(5).toSortedList().toImmutable();
    • toSortedList

      public static <T> Collector<T,​?,​MutableList<T>> toSortedList​(Comparator<? super T> comparator)

      Returns the elements as a MutableList that has been sorted using the specified comparator.

      Examples:

      MutableList<Integer> list1 = Interval.oneTo(5).stream().collect(Collectors2.toSortedList(Comparators.naturalOrder()));
      MutableList<Integer> list2 = Interval.oneTo(5).reduceInPlace(Collectors2.toSortedList(Comparators.naturalOrder()));

      Equivalent to using @RichIterable.toSortedList(Comparator)}

      MutableList<Integer> list = Interval.oneTo(5).toSortedList(Comparators.naturalOrder());
    • toSortedListBy

      public static <T,​ V extends Comparable<? super V>> Collector<T,​?,​MutableList<T>> toSortedListBy​(Function<? super T,​? extends V> function)

      Returns the elements as a MutableList that has been sorted using the specified comparator.

      Examples:

      MutableList<Integer> list1 = Interval.oneTo(5).stream().collect(Collectors2.toSortedListBy(Object::toString));
      MutableList<Integer> list2 = Interval.oneTo(5).reduceInPlace(Collectors2.toSortedListBy(Object::toString));

      Equivalent to using @RichIterable.toSortedListBy(Function)}

      MutableList<Integer> list = Interval.oneTo(5).toSortedListBy(Object::toString);
    • toImmutableSortedList

      public static <T> Collector<T,​?,​ImmutableList<T>> toImmutableSortedList​(Comparator<? super T> comparator)

      Returns the elements as an ImmutableList that has been sorted using the specified comparator.

      Examples:

      ImmutableList<Integer> list1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableSortedList(Comparator.naturalOrder()));
      ImmutableList<Integer> list2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableSortedList(Comparator.naturalOrder()));

      Equivalent to using @RichIterable.toSortedList(Comparator) followed by: @MutableList.toImmutable().

      ImmutableList<Integer> list = Interval.oneTo(5).toSortedList(Comparator.naturalOrder()).toImmutable();
    • toSortedBag

      public static <T> Collector<T,​?,​MutableSortedBag<T>> toSortedBag()

      Returns the elements as a MutableSortedBag.

      Examples:

      MutableSortedBag<Integer> bag1 = Interval.oneTo(5).stream().collect(Collectors2.toSortedBag());
      MutableSortedBag<Integer> bag2 = Interval.oneTo(5).reduceInPlace(Collectors2.toSortedBag());

      Equivalent to using @RichIterable.toSortedBag()}

      MutableSortedBag<Integer> bag = Interval.oneTo(5).toSortedBag();
    • toImmutableSortedBag

      public static <T> Collector<T,​?,​ImmutableSortedBag<T>> toImmutableSortedBag()

      Returns the elements as an ImmutableSortedBag.

      Examples:

      ImmutableSortedBag<Integer> bag1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableSortedBag());
      ImmutableSortedBag<Integer> bag2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableSortedBag());

      Equivalent to using @RichIterable.toSortedBag() followed by: @MutableList.toImmutable().

      ImmutableSortedBag<Integer> bag = Interval.oneTo(5).toSortedBag().toImmutable();
    • toSortedBag

      public static <T> Collector<T,​?,​MutableSortedBag<T>> toSortedBag​(Comparator<? super T> comparator)

      Returns the elements as a MutableSortedBag using the specified comparator.

      Examples:

      MutableSortedBag<Integer> bag1 = Interval.oneTo(5).stream().collect(Collectors2.toSortedBag(Comparators.naturalOrder()));
      MutableSortedBag<Integer> bag2 = Interval.oneTo(5).reduceInPlace(Collectors2.toSortedBag(Comparators.naturalOrder()));

      Equivalent to using @RichIterable.toSortedBag(Comparator)

      MutableSortedBag<Integer> bag = Interval.oneTo(5).toSortedBag(Comparators.naturalOrder());
    • toSortedBagBy

      public static <T,​ V extends Comparable<? super V>> Collector<T,​?,​MutableSortedBag<T>> toSortedBagBy​(Function<? super T,​? extends V> function)

      Returns the elements as a MutableSortedBag using the specified function.

      Examples:

      MutableSortedBag<Integer> bag1 = Interval.oneTo(5).stream().collect(Collectors2.toSortedBagBy(Object::toString));
      MutableSortedBag<Integer> bag2 = Interval.oneTo(5).reduceInPlace(Collectors2.toSortedBagBy(Object::toString));

      Equivalent to using @RichIterable.toSortedBagBy(Function)}

      MutableSortedBag<Integer> bag = Interval.oneTo(5).toSortedBagBy(Object::toString);
    • toImmutableSortedBag

      public static <T> Collector<T,​?,​ImmutableSortedBag<T>> toImmutableSortedBag​(Comparator<? super T> comparator)

      Returns the elements as an ImmutableSortedBag using the specified comparator.

      Examples:

      ImmutableSortedBag<Integer> bag1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableSortedBag(Comparator.naturalOrder()));
      ImmutableSortedBag<Integer> bag1 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableSortedBag(Comparator.naturalOrder()));

      Equivalent to using @RichIterable.toSortedBag(Comparator) followed by: @MutableBag.toImmutable().

      ImmutableSortedBag<Integer> bag = Interval.oneTo(5).toSortedBag(Comparator.naturalOrder()).toImmutable();
    • toStack

      public static <T> Collector<T,​?,​MutableStack<T>> toStack()

      Returns the elements as a MutableStack.

      Examples:

      MutableStack<Integer> stack1 = Interval.oneTo(5).stream().collect(Collectors2.toStack());
      MutableStack<Integer> stack2 = Interval.oneTo(5).reduceInPlace(Collectors2.toStack());

      Equivalent to using @OrderedIterable.toStack()}

      MutableStack<Integer> stack = Interval.oneTo(5).toList().toStack();
    • toImmutableStack

      public static <T> Collector<T,​?,​ImmutableStack<T>> toImmutableStack()

      Returns the elements as an ImmutableStack.

      Examples:

      ImmutableStack<Integer> stack1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableStack());
      ImmutableStack<Integer> stack2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableStack());

      Equivalent to using @OrderedIterable.toStack() followed by: @StackIterable.toImmutable()}

      ImmutableStack<Integer> stack = Interval.oneTo(5).toList().toStack().toImmutable();
    • toBiMap

      public static <T,​ K,​ V> Collector<T,​?,​MutableBiMap<K,​V>> toBiMap​(Function<? super T,​? extends K> keyFunction, Function<? super T,​? extends V> valueFunction)

      Returns the elements as a MutableBiMap applying the keyFunction and valueFunction to each element.

      Examples:

      BiMap<Integer, String> biMap1 = Interval.oneTo(5).stream().collect(Collectors2.toBiMap(Functions.identity(), Object::toString));
      BiMap<Integer, String> biMap1 = Interval.oneTo(5).reduceInPlace(Collectors2.toBiMap(Functions.identity(), Object::toString));
    • toImmutableBiMap

      public static <T,​ K,​ V> Collector<T,​?,​ImmutableBiMap<K,​V>> toImmutableBiMap​(Function<? super T,​? extends K> keyFunction, Function<? super T,​? extends V> valueFunction)

      Returns the elements as an ImmutableBiMap applying the keyFunction and valueFunction to each element.

      Examples:

      MutableBiMap<Integer, String> biMap1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableBiMap(Functions.identity(), Object::toString));
      MutableBiMap<Integer, String> biMap2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableBiMap(Functions.identity(), Object::toString));
    • toMap

      public static <T,​ K,​ V> Collector<T,​?,​MutableMap<K,​V>> toMap​(Function<? super T,​? extends K> keyFunction, Function<? super T,​? extends V> valueFunction)

      Returns the elements as a MutableMap applying the keyFunction and valueFunction to each element.

      Examples:

      MutableMap<Integer, String> map1 = Interval.oneTo(5).stream().collect(Collectors2.toMap(Functions.identity(), Object::toString));
      MutableMap<Integer, String> map2 = Interval.oneTo(5).reduceInPlace(Collectors2.toMap(Functions.identity(), Object::toString));

      Equivalent to using @RichIterable.toMap(Function, Function)

      MutableMap<Integer, String> map = Interval.oneTo(5).toMap(Functions.identity(), Object::toString);
    • toImmutableMap

      public static <T,​ K,​ V> Collector<T,​?,​ImmutableMap<K,​V>> toImmutableMap​(Function<? super T,​? extends K> keyFunction, Function<? super T,​? extends V> valueFunction)

      Returns the elements as an ImmutableMap applying the keyFunction and valueFunction to each element.

      Examples:

      ImmutableMap<Integer, String> map1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableMap(Functions.identity(), Object::toString));
      ImmutableMap<Integer, String> map2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableMap(Functions.identity(), Object::toString));

      Equivalent to using @RichIterable.toMap(Function, Function)

      ImmutableMap<Integer, String> map = Interval.oneTo(5).toMap(Functions.identity(), Object::toString).toImmutable();
    • countBy

      public static <T,​ K> Collector<T,​?,​MutableBag<K>> countBy​(Function<? super T,​? extends K> function)
      Returns the counts of all of the values returned by applying the specified function to each item of the Stream.
      Since:
      9.1
    • countByEach

      public static <T,​ K> Collector<T,​?,​MutableBag<K>> countByEach​(Function<? super T,​? extends Iterable<K>> function)

      Same as countBy(Function), except the result of applying the specified function will return a collection of keys for each value.

      Since:
      9.2
    • groupBy

      public static <T,​ K,​ R extends MutableMultimap<K,​ T>> Collector<T,​?,​R> groupBy​(Function<? super T,​? extends K> groupBy, Supplier<R> supplier)

      Returns the elements as an MutableMultimap grouping each element using the specified groupBy Function.

      Examples:

      MutableListMultimap<String, Integer> multimap1 = Interval.oneTo(5).stream().collect(Collectors2.groupBy(Object::toString, Multimaps.mutable.list::empty));
      MutableListMultimap<String, Integer> multimap2 = Interval.oneTo(5).reduceInPlace(Collectors2.groupBy(Object::toString, Multimaps.mutable.list::empty));

      Equivalent to using @RichIterable.groupBy(Function, MutableMultimap)

      MutableListMultimap<String, Integer> multimap = Interval.oneTo(5).groupBy(Object::toString, Multimaps.mutable.list.empty());
    • groupByEach

      public static <T,​ K,​ R extends MutableMultimap<K,​ T>> Collector<T,​?,​R> groupByEach​(Function<? super T,​? extends Iterable<K>> groupBy, Supplier<R> supplier)

      Same as groupBy(Function, Supplier), except the result of evaluating groupBy function will return a collection of keys for each value.

      Equivalent to using @RichIterable.groupByEach(Function, MutableMultimap)

    • groupByUniqueKey

      public static <T,​ K,​ R extends MutableMapIterable<K,​ T>> Collector<T,​?,​R> groupByUniqueKey​(Function<? super T,​? extends K> groupBy, Supplier<R> supplier)

      Same as groupBy(Function, Supplier), except the result of evaluating groupBy function should return a unique key, or else an exception is thrown.

      Equivalent to using RichIterable.groupByUniqueKey(Function, MutableMapIterable)

    • groupByAndCollect

      public static <T,​ K,​ V,​ R extends MutableMultimap<K,​ V>> Collector<T,​?,​R> groupByAndCollect​(Function<? super T,​? extends K> groupBy, Function<? super T,​? extends V> valueFunction, Supplier<R> supplier)

      Returns the elements as an MutableMultimap grouping each element using the specified groupBy Function and converting each element to the value returned by applying the specified Function valueFunction.

      Examples:

      MutableListMultimap<String, String> multimap1 = Interval.oneTo(5).stream().collect(Collectors2.groupByAndCollect(Object::toString, Object::toString, Multimaps.mutable.list::empty));
      MutableListMultimap<String, String> multimap2 = Interval.oneTo(5).reduceInPlace(Collectors2.groupByAndCollect(Object::toString, Object::toString, Multimaps.mutable.list::empty));
    • aggregateBy

      public static <T,​ K,​ R extends MutableMapIterable<K,​ T>> Collector<T,​?,​R> aggregateBy​(Function<? super T,​? extends K> groupBy, Function0<? extends T> zeroValueFactory, Function2<? super T,​? super T,​? extends T> aggregator, Supplier<R> supplier)
      Groups the elements using the groupBy function and all the elements that map to the same key are aggregated together using the aggregator function. The second parameter, the zeroValueFactory function, creates the initial value in each aggregation. Aggregate results are allowed to be immutable as they will be replaced in the map.
    • toListMultimap

      public static <T,​ K> Collector<T,​?,​MutableListMultimap<K,​T>> toListMultimap​(Function<? super T,​? extends K> groupBy)

      Returns the elements as an MutableListMultimap grouping each element using the specified groupBy Function.

      Examples:

      MutableListMultimap<String, Integer> multimap1 = Interval.oneTo(5).stream().collect(Collectors2.toListMultimap(Object::toString));
      MutableListMultimap<String, Integer> multimap2 = Interval.oneTo(5).reduceInPlace(Collectors2.toListMultimap(Object::toString));
    • toListMultimap

      public static <T,​ K,​ V> Collector<T,​?,​MutableListMultimap<K,​V>> toListMultimap​(Function<? super T,​? extends K> groupBy, Function<? super T,​? extends V> valueFunction)

      Returns the elements as an MutableListMultimap grouping each element using the specified groupBy Function and converting each element to the value returned by applying the specified Function valueFunction.

      Examples:

      MutableListMultimap<String, String> multimap1 = Interval.oneTo(5).stream().collect(Collectors2.toListMultimap(Object::toString, Object::toString));
      MutableListMultimap<String, String> multimap2 = Interval.oneTo(5).reduceInPlace(Collectors2.toListMultimap(Object::toString, Object::toString));
    • toSetMultimap

      public static <T,​ K> Collector<T,​?,​MutableSetMultimap<K,​T>> toSetMultimap​(Function<? super T,​? extends K> groupBy)

      Returns the elements as an MutableSetMultimap grouping each element using the specified groupBy Function.

      Examples:

      MutableSetMultimap<String, Integer> multimap1 = Interval.oneTo(5).stream().collect(Collectors2.toSetMultimap(Object::toString));
      MutableSetMultimap<String, Integer> multimap2 = Interval.oneTo(5).reduceInPlace(Collectors2.toSetMultimap(Object::toString));
    • toSetMultimap

      public static <T,​ K,​ V> Collector<T,​?,​MutableSetMultimap<K,​V>> toSetMultimap​(Function<? super T,​? extends K> groupBy, Function<? super T,​? extends V> valueFunction)

      Returns the elements as an MutableSetMultimap grouping each element using the specified groupBy Function and converting each element to the value returned by applying the specified Function valueFunction.

      Examples:

      MutableSetMultimap<String, String> multimap1 = Interval.oneTo(5).stream().collect(Collectors2.toSetMultimap(Object::toString, Object::toString));
      MutableSetMultimap<String, String> multimap2 = Interval.oneTo(5).reduceInPlace(Collectors2.toSetMultimap(Object::toString, Object::toString));
    • toBagMultimap

      public static <T,​ K> Collector<T,​?,​MutableBagMultimap<K,​T>> toBagMultimap​(Function<? super T,​? extends K> groupBy)

      Returns the elements as an MutableBagMultimap grouping each element using the specified groupBy Function.

      Examples:

      MutableBagMultimap<String, Integer> multimap1 = Interval.oneTo(5).stream().collect(Collectors2.toBagMultimap(Object::toString));
      MutableBagMultimap<String, Integer> multimap2 = Interval.oneTo(5).reduceInPlace(Collectors2.toBagMultimap(Object::toString));
    • toBagMultimap

      public static <T,​ K,​ V> Collector<T,​?,​MutableBagMultimap<K,​V>> toBagMultimap​(Function<? super T,​? extends K> groupBy, Function<? super T,​? extends V> valueFunction)

      Returns the elements as an MutableBagMultimap grouping each element using the specified groupBy Function and converting each element to the value returned by applying the specified Function valueFunction.

      Examples:

      MutableBagMultimap<String, String> multimap1 = Interval.oneTo(5).stream().collect(Collectors2.toBagMultimap(Object::toString, Object::toString));
      MutableBagMultimap<String, String> multimap2 = Interval.oneTo(5).reduceInPlace(Collectors2.toBagMultimap(Object::toString, Object::toString));
    • toImmutableListMultimap

      public static <T,​ K> Collector<T,​?,​ImmutableListMultimap<K,​T>> toImmutableListMultimap​(Function<? super T,​? extends K> groupBy)

      Returns the elements as an ImmutableListMultimap grouping each element using the specified groupBy Function.

      Examples:

      ImmutableListMultimap<String, Integer> multimap1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableListMultimap(Object::toString));
      ImmutableListMultimap<String, Integer> multimap2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableListMultimap(Object::toString));
    • toImmutableListMultimap

      public static <T,​ K,​ V> Collector<T,​?,​ImmutableListMultimap<K,​V>> toImmutableListMultimap​(Function<? super T,​? extends K> groupBy, Function<? super T,​? extends V> valueFunction)

      Returns the elements as an ImmutableListMultimap grouping each element using the specified groupBy Function and converting each element to the value returned by applying the specified Function valueFunction.

      Examples:

      ImmutableListMultimap<String, String> multimap1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableListMultimap(Object::toString, Object::toString));
      ImmutableListMultimap<String, String> multimap2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableListMultimap(Object::toString, Object::toString));
    • toImmutableSetMultimap

      public static <T,​ K> Collector<T,​?,​ImmutableSetMultimap<K,​T>> toImmutableSetMultimap​(Function<? super T,​? extends K> groupBy)

      Returns the elements as an ImmutableSetMultimap grouping each element using the specified groupBy Function.

      Examples:

      ImmutableSetMultimap<String, Integer> multimap1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableSetMultimap(Object::toString));
      ImmutableSetMultimap<String, Integer> multimap2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableSetMultimap(Object::toString));
    • toImmutableSetMultimap

      public static <T,​ K,​ V> Collector<T,​?,​ImmutableSetMultimap<K,​V>> toImmutableSetMultimap​(Function<? super T,​? extends K> groupBy, Function<? super T,​? extends V> valueFunction)

      Returns the elements as an ImmutableSetMultimap grouping each element using the specified groupBy Function and converting each element to the value returned by applying the specified Function valueFunction.

      Examples:

      ImmutableSetMultimap<String, String> multimap1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableSetMultimap(Object::toString, Object::toString));
      ImmutableSetMultimap<String, String> multimap2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableSetMultimap(Object::toString, Object::toString));
    • toImmutableBagMultimap

      public static <T,​ K> Collector<T,​?,​ImmutableBagMultimap<K,​T>> toImmutableBagMultimap​(Function<? super T,​? extends K> groupBy)

      Returns the elements as an ImmutableBagMultimap grouping each element using the specified groupBy Function.

      Examples:

      ImmutableBagMultimap<String, Integer> multimap1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableBagMultimap(Object::toString));
      ImmutableBagMultimap<String, Integer> multimap2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableBagMultimap(Object::toString));
    • toImmutableBagMultimap

      public static <T,​ K,​ V> Collector<T,​?,​ImmutableBagMultimap<K,​V>> toImmutableBagMultimap​(Function<? super T,​? extends K> groupBy, Function<? super T,​? extends V> valueFunction)

      Returns the elements as an ImmutableBagMultimap grouping each element using the specified groupBy Function and converting each element to the value returned by applying the specified Function valueFunction.

      Examples:

      ImmutableBagMultimap<String, String> multimap1 = Interval.oneTo(5).stream().collect(Collectors2.toImmutableBagMultimap(Object::toString, Object::toString));
      ImmutableBagMultimap<String, String> multimap2 = Interval.oneTo(5).reduceInPlace(Collectors2.toImmutableBagMultimap(Object::toString, Object::toString));
    • chunk

      public static <T> Collector<T,​?,​MutableList<MutableList<T>>> chunk​(int size)

      Partitions elements in fixed size chunks.

      Examples:

      MutableList<MutableList<Integer>> chunks1 = Interval.oneTo(10).stream().collect(Collectors2.chunk(2));
      MutableList<MutableList<Integer>> chunks2 = Interval.oneTo(10).reduceInPlace(Collectors2.chunk(2));

      Equivalent to using @RichIterable.chunk(int)

      LazyIterable<RichIterable<Integer>> chunks = Interval.oneTo(10).chunk(2);
    • zip

      public static <T,​ S> Collector<T,​?,​MutableList<Pair<T,​S>>> zip​(Iterable<S> other)

      Returns a MutableList formed from this stream of elements and another Iterable by combining corresponding elements in pairs.

      If one of the two Iterables is longer than the other, its remaining elements are ignored.

      Examples:

      MutableList<Pair<Integer, Integer>> zipped1 = Interval.oneTo(10).stream().collect(Collectors2.zip(Interval.oneTo(10)));
      MutableList<Pair<Integer, Integer>> zipped2 = Interval.oneTo(10).reduceInPlace(Collectors2.zip(Interval.oneTo(10)));

      Equivalent to using @RichIterable.zip(Iterable)

      LazyIterable<Pair<Integer, Integer>> zip = Interval.oneTo(10).zip(Interval.oneTo(10));
    • zipWithIndex

      public static <T> Collector<T,​?,​MutableList<ObjectIntPair<T>>> zipWithIndex()

      Returns a MutableList of pairs formed from this stream of elements its indices.

      Examples:

      MutableList<ObjectIntPair<Integer>> zipWithIndex1 = Interval.oneTo(10).stream().collect(Collectors2.zipWithIndex());
      MutableList<ObjectIntPair<Integer>> zipWithIndex2 = Interval.oneTo(10).reduceInPlace(Collectors2.zipWithIndex());

      Equivalent to using @RichIterable.zipWithIndex()

      LazyIterable<Pair<Integer, Integer>> zipWithIndex = Interval.oneTo(10).zipWithIndex();
    • sumByInt

      public static <T,​ V> Collector<T,​?,​MutableObjectLongMap<V>> sumByInt​(Function<? super T,​? extends V> groupBy, IntFunction<? super T> function)

      Groups and sums the values using the two specified functions.

      Examples:

      MutableObjectLongMap<Integer> sumBy1 = Interval.oneTo(10).stream().collect(Collectors2.sumByInt(each -> Integer.valueOf(each % 2), Integer::intValue));
      MutableObjectLongMap<Integer> sumBy2 = Interval.oneTo(10).reduceInPlace(Collectors2.sumByInt(each -> Integer.valueOf(each % 2), Integer::intValue));

      Equivalent to using @RichIterable.sumByInt(Function, IntFunction)

      ObjectLongMap<Integer> sumBy = Interval.oneTo(10).sumByInt(each -> Integer.valueOf(each % 2), Integer::intValue));
    • sumByLong

      public static <T,​ V> Collector<T,​?,​MutableObjectLongMap<V>> sumByLong​(Function<? super T,​? extends V> groupBy, LongFunction<? super T> function)

      Groups and sums the values using the two specified functions.

      Examples:

      MutableObjectLongMap<Long> sumBy1 = Interval.oneTo(10).stream().collect(Collectors2.sumByLong(each -> Long.valueOf(each % 2), Integer::longValue));
      MutableObjectLongMap<Long> sumBy2 = Interval.oneTo(10).reduceInPlace(Collectors2.sumByLong(each -> Long.valueOf(each % 2), Integer::longValue));

      Equivalent to using @RichIterable.sumByLong(Function, LongFunction)

      ObjectLongMap<Long> sumBy = Interval.oneTo(10).sumByLong(each -> Long.valueOf(each % 2), Integer::longValue));
    • sumByFloat

      public static <T,​ V> Collector<T,​?,​MutableObjectDoubleMap<V>> sumByFloat​(Function<? super T,​? extends V> groupBy, FloatFunction<? super T> function)

      Groups and sums the values using the two specified functions.

      Examples:

      MutableObjectDoubleMap<Integer> sumBy1 = Interval.oneTo(10).stream().collect(Collectors2.sumByFloat(each -> ((int)each % 2), Integer::floatValue));
      MutableObjectDoubleMap<Integer> sumBy2 = Interval.oneTo(10).reduceInPlace(Collectors2.sumByFloat(each -> ((int)each % 2), Integer::floatValue));

      Equivalent to using @RichIterable.sumByFloat(Function, FloatFunction)

      ObjectDoubleMap<Integer> sumBy = Interval.oneTo(10).sumByFloat(each -> ((int)each % 2), Integer::floatValue));
    • sumByDouble

      public static <T,​ V> Collector<T,​?,​MutableObjectDoubleMap<V>> sumByDouble​(Function<? super T,​? extends V> groupBy, DoubleFunction<? super T> function)

      Groups and sums the values using the two specified functions.

      Examples:

      MutableObjectDoubleMap<Integer> sumBy1 = Interval.oneTo(10).stream().collect(Collectors2.sumByDouble(each -> ((int)each % 2), Integer::doubleValue));
      MutableObjectDoubleMap<Integer> sumBy2 = Interval.oneTo(10).reduceInPlace(Collectors2.sumByDouble(each -> ((int)each % 2), Integer::doubleValue));

      Equivalent to using @RichIterable.sumByDouble(Function, DoubleFunction)

      ObjectDoubleMap<Integer> sumBy = Interval.oneTo(10).sumByDouble(each -> ((int)each % 2), Integer::doubleValue));
    • sumByBigDecimal

      public static <T,​ V> Collector<T,​?,​MutableMap<V,​BigDecimal>> sumByBigDecimal​(Function<? super T,​? extends V> groupBy, Function<? super T,​BigDecimal> function)

      Groups and sums the values using the two specified functions.

      Examples:

      MutableMap<Integer, BigDecimal> sumBy1 = Interval.oneTo(10).stream().collect(Collectors2.sumByBigDecimal(each -> (each.intValue() % 2), BigDecimal::new));
      MutableMap<Integer, BigDecimal> sumBy2 = Interval.oneTo(10).reduceInPlace(Collectors2.sumByBigDecimal(each -> (each.intValue() % 2), BigDecimal::new));

      Equivalent to using @Iterate.sumByBigDecimal(Iterable, Function, Function)

      MutableMap<Integer, BigDecimal> sumBy = Iterate.sumByBigDecimal(Interval.oneTo(10), each -> (each.intValue() % 2), BigDecimal::new));
      Since:
      8.1
    • sumByBigInteger

      public static <T,​ V> Collector<T,​?,​MutableMap<V,​BigInteger>> sumByBigInteger​(Function<? super T,​? extends V> groupBy, Function<? super T,​BigInteger> function)

      Groups and sums the values using the two specified functions.

      Examples:

      MutableMap<Integer, BigInteger> sumBy1 = Interval.oneTo(10).stream().collect(Collectors2.sumByBigInteger(each -> (each.intValue() % 2), each -> BigInteger.valueOf(each.longValue())));
      MutableMap<Integer, BigInteger> sumBy2 = Interval.oneTo(10).reduceInPlace(Collectors2.sumByBigInteger(each -> (each.intValue() % 2), each -> BigInteger.valueOf(each.longValue())));

      Equivalent to using @Iterate.sumByBigInteger(Iterable, Function, Function)

      MutableMap<Integer, BigInteger> sumBy = Iterate.sumByBigInteger(Interval.oneTo(10), each -> (each.intValue() % 2), each -> BigInteger.valueOf(each.longValue())));
      Since:
      8.1
    • select

      public static <T,​ R extends Collection<T>> Collector<T,​?,​R> select​(Predicate<? super T> predicate, Supplier<R> supplier)

      Returns all elements of the stream that return true when evaluating the predicate. This method is also commonly called filter. The new collection is created as the result of evaluating the provided Supplier.

      Examples:

      MutableList<Integer> evens1 = Interval.oneTo(10).stream().collect(Collectors2.select(e -> e % 2 == 0, Lists.mutable::empty));
      MutableList<Integer> evens2 = Interval.oneTo(10).reduceInPlace(Collectors2.select(e -> e % 2 == 0, Lists.mutable::empty));

      Equivalent to using @RichIterable.select(Predicate, Collection)

      MutableList<Integer> evens = Interval.oneTo(10).select(e -> e % 2 == 0, Lists.mutable.empty());
    • selectWith

      public static <T,​ P,​ R extends Collection<T>> Collector<T,​?,​R> selectWith​(Predicate2<? super T,​? super P> predicate, P parameter, Supplier<R> supplier)

      Returns all elements of the stream that return true when evaluating the predicate with the parameter. The new collection is created as the result of evaluating the provided Supplier.

      Examples:

      MutableList<Integer> evens1 = Interval.oneTo(10).stream().collect(Collectors2.selectWith((e, p) -> e % p == 0, 2, Lists.mutable::empty));
      MutableList<Integer> evens2 = Interval.oneTo(10).reduceInPlace(Collectors2.selectWith((e, p) -> e % p == 0, 2, Lists.mutable::empty));

      Equivalent to using @RichIterable.selectWith(Predicate2, Object, Collection)

      MutableList<Integer> evens = Interval.oneTo(10).selectWith((e, p) -> e % p == 0, 2, Lists.mutable.empty());
    • reject

      public static <T,​ R extends Collection<T>> Collector<T,​?,​R> reject​(Predicate<? super T> predicate, Supplier<R> supplier)

      Returns all elements of the stream that return false when evaluating the predicate. This method is also commonly called filterNot. The new collection is created as the result of evaluating the provided Supplier.

      Examples:

      MutableList<Integer> odds1 = Interval.oneTo(10).stream().collect(Collectors2.reject(e -> e % 2 == 0, Lists.mutable::empty));
      MutableList<Integer> odds2 = Interval.oneTo(10).reduceInPlace(Collectors2.reject(e -> e % 2 == 0, Lists.mutable::empty));

      Equivalent to using @RichIterable.reject(Predicate, Collection)

      MutableList<Integer> odds = Interval.oneTo(10).reject(e -> e % 2 == 0, Lists.mutable.empty());
    • rejectWith

      public static <T,​ P,​ R extends Collection<T>> Collector<T,​?,​R> rejectWith​(Predicate2<? super T,​? super P> predicate, P parameter, Supplier<R> supplier)

      Returns all elements of the stream that return false when evaluating the predicate with the parameter. The new collection is created as the result of evaluating the provided Supplier.

      Examples:

      MutableList<Integer> odds1 = Interval.oneTo(10).stream().collect(Collectors2.rejectWith((e, p) -> e % p == 0, 2, Lists.mutable::empty));
      MutableList<Integer> odds2 = Interval.oneTo(10).reduceInPlace(Collectors2.rejectWith((e, p) -> e % p == 0, 2, Lists.mutable::empty));

      Equivalent to using @RichIterable.rejectWith(Predicate2, Object, Collection)

      MutableList<Integer> odds = Interval.oneTo(10).rejectWith((e, p) -> e % p == 0, 2, Lists.mutable.empty());
    • partition

      public static <T,​ R extends PartitionMutableCollection<T>> Collector<T,​?,​R> partition​(Predicate<? super T> predicate, Supplier<R> supplier)

      Returns all elements of the stream split into a PartitionMutableCollection after evaluating the predicate. The new PartitionMutableCollection is created as the result of evaluating the provided Supplier.

      Examples:

      PartitionMutableList<Integer> evensAndOdds1 = Interval.oneTo(10).stream().collect(Collectors2.partition(e -> e % 2 == 0, PartitionFastList::new));
      PartitionMutableList<Integer> evensAndOdds2 = Interval.oneTo(10).reduceInPlace(Collectors2.partition(e -> e % 2 == 0, PartitionFastList::new));

      Equivalent to using @RichIterable.partition(Predicate)

      PartitionMutableList<Integer> evensAndOdds = Interval.oneTo(10).partition(e -> e % 2 == 0);
    • partitionWith

      public static <T,​ P,​ R extends PartitionMutableCollection<T>> Collector<T,​?,​R> partitionWith​(Predicate2<? super T,​? super P> predicate, P parameter, Supplier<R> supplier)

      Returns all elements of the stream split into a PartitionMutableCollection after evaluating the predicate. The new PartitionMutableCollection is created as the result of evaluating the provided Supplier.

      Examples:

      PartitionMutableList<Integer> evensAndOdds1 = Interval.oneTo(10).stream().collect(Collectors2.partitionWith((e, p) -> e % p == 0, 2, PartitionFastList::new));
      PartitionMutableList<Integer> evensAndOdds2 = Interval.oneTo(10).reduceInPlace(Collectors2.partitionWith((e, p) -> e % p == 0, 2, PartitionFastList::new));

      Equivalent to using @RichIterable.partitionWith(Predicate2, Object)

      PartitionMutableList<Integer> evensAndOdds = Interval.oneTo(10).partitionWith((e, p) -> e % p == 0, 2);
    • collect

      public static <T,​ V,​ R extends Collection<V>> Collector<T,​?,​R> collect​(Function<? super T,​? extends V> function, Supplier<R> supplier)

      Returns a new collection with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map. The new collection is created as the result of evaluating the provided Supplier.

      Examples:

      MutableList<String> collect1 = Interval.oneTo(10).stream().collect(Collectors2.collect(Object::toString, Lists.mutable::empty));
      MutableList<String> collect2 = Interval.oneTo(10).reduceInPlace(Collectors2.collect(Object::toString, Lists.mutable::empty));

      Equivalent to using @RichIterable.collect(Function, Collection)

      MutableList<String> collect = Interval.oneTo(10).collect(Object::toString, Lists.mutable.empty());
    • flatCollect

      public static <T,​ V,​ R extends Collection<V>> Collector<T,​?,​R> flatCollect​(Function<? super T,​? extends Iterable<V>> function, Supplier<R> supplier)
      The method flatCollect is a special case of collect(Function, Supplier). With collect, when the Function returns a collection, the result is a collection of collections. flatCollect outputs a single "flattened" collection instead. This method is commonly called flatMap.

      Example:

      
       List<MutableList<String>> lists =
           Lists.mutable.with(
               Lists.mutable.with("a", "b"),
               Lists.mutable.with("c", "d"),
               Lists.mutable.with("e"));
      
       MutableList<String> flattened =
           lists.stream().collect(Collectors2.flatCollect(l -> l, Lists.mutable::empty));
      
       Assert.assertEquals(Lists.mutable.with("a", "b", "c", "d", "e"), flattened);
    • collectWith

      public static <T,​ P,​ V,​ R extends Collection<V>> Collector<T,​?,​R> collectWith​(Function2<? super T,​? super P,​? extends V> function, P parameter, Supplier<R> supplier)

      Returns a new collection with the results of applying the specified function on each element of the source collection with the specified parameter. This method is also commonly called transform or map. The new collection is created as the result of evaluating the provided Supplier.

      Examples:

      MutableList<Integer> collect1 = Interval.oneTo(10).stream().collect(Collectors2.collectWith(Integer::sum, Integer.valueOf(10), Lists.mutable::empty));
      MutableList<Integer> collect2 = Interval.oneTo(10).reduceInPlace(Collectors2.collectWith(Integer::sum, Integer.valueOf(10), Lists.mutable::empty));

      Equivalent to using @RichIterable.collectWith(Function2, Object, Collection)

      MutableList<Integer> collect = Interval.oneTo(10).collectWith(Integer::sum, Integer.valueOf(10), Lists.mutable.empty());
    • collectBoolean

      public static <T,​ R extends MutableBooleanCollection> Collector<T,​?,​R> collectBoolean​(BooleanFunction<? super T> function, Supplier<R> supplier)

      Returns a new MutableBooleanCollection with the results of applying the specified BooleanFunction on each element of the source. The new collection is created as the result of evaluating the provided Supplier.

      Examples:

      MutableBooleanList collect1 = Interval.oneTo(10).stream().collect(Collectors2.collectBoolean(each -> each % 2 == 0, BooleanLists.mutable::empty));
      MutableBooleanList collect2 = Interval.oneTo(10).reduceInPlace(Collectors2.collectBoolean(each -> each % 2 == 0, BooleanLists.mutable::empty));

      Equivalent to using @RichIterable.collectBoolean(BooleanFunction, MutableBooleanCollection)

      MutableBooleanList collect = Interval.oneTo(10).collectBoolean(each -> each % 2 == 0, BooleanLists.mutable.empty());
    • collectByte

      public static <T,​ R extends MutableByteCollection> Collector<T,​?,​R> collectByte​(ByteFunction<? super T> function, Supplier<R> supplier)

      Returns a new MutableByteCollection with the results of applying the specified ByteFunction on each element of the source. The new collection is created as the result of evaluating the provided Supplier.

      Examples:

      MutableByteList collect1 = Interval.oneTo(10).stream().collect(Collectors2.collectByte(each -> (byte) (each % Byte.MAX_VALUE), ByteLists.mutable::empty));
      MutableByteList collect2 = Interval.oneTo(10).reduceInPlace(Collectors2.collectByte(each -> (byte) (each % Byte.MAX_VALUE), ByteLists.mutable::empty));

      Equivalent to using @RichIterable.collectByte(ByteFunction, MutableByteCollection)

      MutableByteList collect = Interval.oneTo(10).collectByte(each -> (byte) (each % Byte.MAX_VALUE), ByteLists.mutable.empty());
    • collectChar

      public static <T,​ R extends MutableCharCollection> Collector<T,​?,​R> collectChar​(CharFunction<? super T> function, Supplier<R> supplier)

      Returns a new MutableCharCollection with the results of applying the specified CharFunction on each element of the source. The new collection is created as the result of evaluating the provided Supplier.

      Examples:

      MutableCharList collect1 = Interval.oneTo(10).stream().collect(Collectors2.collectChar(each -> (char) (each % Character.MAX_VALUE), CharLists.mutable::empty));
      MutableCharList collect2 = Interval.oneTo(10).reduceInPlace(Collectors2.collectChar(each -> (char) (each % Character.MAX_VALUE), CharLists.mutable::empty));

      Equivalent to using @RichIterable.collectChar(CharFunction, MutableCharCollection)

      MutableCharList collect = Interval.oneTo(10).collectChar(each -> (char) (each % Character.MAX_VALUE), CharLists.mutable.empty());
    • collectShort

      public static <T,​ R extends MutableShortCollection> Collector<T,​?,​R> collectShort​(ShortFunction<? super T> function, Supplier<R> supplier)

      Returns a new MutableShortCollection with the results of applying the specified ShortFunction on each element of the source. The new collection is created as the result of evaluating the provided Supplier.

      Examples:

      MutableShortList collect1 = Interval.oneTo(10).stream().collect(Collectors2.collectShort(each -> (short) (each % Short.MAX_VALUE), ShortLists.mutable::empty));
      MutableShortList collect2 = Interval.oneTo(10).reduceInPlace(Collectors2.collectShort(each -> (short) (each % Short.MAX_VALUE), ShortLists.mutable::empty));

      Equivalent to using @RichIterable.collectShort(ShortFunction, MutableShortCollection)

      MutableShortList collect = Interval.oneTo(10).collectShort(each -> (short) (each % Short.MAX_VALUE), ShortLists.mutable.empty());
    • collectInt

      public static <T,​ R extends MutableIntCollection> Collector<T,​?,​R> collectInt​(IntFunction<? super T> function, Supplier<R> supplier)

      Returns a new MutableIntCollection with the results of applying the specified IntFunction on each element of the source. The new collection is created as the result of evaluating the provided Supplier.

      Examples:

      MutableIntList collect1 = Interval.oneTo(10).stream().collect(Collectors2.collectInt(each -> each, IntLists.mutable::empty));
      MutableIntList collect2 = Interval.oneTo(10).reduceInPlace(Collectors2.collectInt(each -> each, IntLists.mutable::empty));

      Equivalent to using @RichIterable.collectInt(IntFunction, MutableIntCollection)

      MutableIntList collect = Interval.oneTo(10).collectInt(each -> each, IntLists.mutable.empty());
    • collectFloat

      public static <T,​ R extends MutableFloatCollection> Collector<T,​?,​R> collectFloat​(FloatFunction<? super T> function, Supplier<R> supplier)

      Returns a new MutableFloatCollection with the results of applying the specified FloatFunction on each element of the source. The new collection is created as the result of evaluating the provided Supplier.

      Examples:

      MutableFloatList collect1 = Interval.oneTo(10).stream().collect(Collectors2.collectFloat(each -> (float) each, FloatLists.mutable::empty));
      MutableFloatList collect2 = Interval.oneTo(10).reduceInPlace(Collectors2.collectFloat(each -> (float) each, FloatLists.mutable::empty));

      Equivalent to using @RichIterable.collectFloat(FloatFunction, MutableFloatCollection)

      MutableFloatList collect = Interval.oneTo(10).collectFloat(each -> (float) each, FloatLists.mutable.empty());
    • collectLong

      public static <T,​ R extends MutableLongCollection> Collector<T,​?,​R> collectLong​(LongFunction<? super T> function, Supplier<R> supplier)

      Returns a new MutableLongCollection with the results of applying the specified LongFunction on each element of the source. The new collection is created as the result of evaluating the provided Supplier.

      Examples:

      MutableLongList collect1 = Interval.oneTo(10).stream().collect(Collectors2.collectLong(each -> (long) each, LongLists.mutable::empty));
      MutableLongList collect2 = Interval.oneTo(10).reduceInPlace(Collectors2.collectLong(each -> (long) each, LongLists.mutable::empty));

      Equivalent to using @RichIterable.collectLong(LongFunction, MutableLongCollection)

      MutableLongList collect = Interval.oneTo(10).collectLong(each -> (long) each, LongLists.mutable.empty());
    • collectDouble

      public static <T,​ R extends MutableDoubleCollection> Collector<T,​?,​R> collectDouble​(DoubleFunction<? super T> function, Supplier<R> supplier)

      Returns a new MutableDoubleCollection with the results of applying the specified DoubleFunction on each element of the source. The new collection is created as the result of evaluating the provided Supplier.

      Examples:

      MutableDoubleList collect1 = Interval.oneTo(10).stream().collect(Collectors2.collectDouble(each -> (double) each, DoubleLists.mutable::empty));
      MutableDoubleList collect2 = Interval.oneTo(10).reduceInPlace(Collectors2.collectDouble(each -> (double) each, DoubleLists.mutable::empty));

      Equivalent to using @RichIterable.collectDouble(DoubleFunction, MutableDoubleCollection)

      MutableDoubleList collect = Interval.oneTo(10).collectDouble(each -> (double) each, DoubleLists.mutable.empty());
    • summarizingBigDecimal

      public static <T> Collector<T,​?,​BigDecimalSummaryStatistics> summarizingBigDecimal​(Function<? super T,​BigDecimal> function)
      Returns a BigDecimalSummaryStatistics applying the specified function to each element of the stream or collection.
      Since:
      8.1
    • summarizingBigInteger

      public static <T> Collector<T,​?,​BigIntegerSummaryStatistics> summarizingBigInteger​(Function<? super T,​BigInteger> function)
      Returns a BigIntegerSummaryStatistics applying the specified function to each element of the stream or collection.
      Since:
      8.1
    • summingBigDecimal

      public static <T> Collector<T,​?,​BigDecimal> summingBigDecimal​(Function<? super T,​BigDecimal> function)
      Returns a BigDecimal sum applying the specified function to each element of the stream or collection.
      Since:
      8.1
    • summingBigInteger

      public static <T> Collector<T,​?,​BigInteger> summingBigInteger​(Function<? super T,​BigInteger> function)
      Returns a BigInteger sum applying the specified function to each element of the stream or collection.
      Since:
      8.1