インタフェース
java.util.stream.Collectorの使用

Collectorを使用しているパッケージ
パッケージ
説明
コレクションに対するマップ-リデュース変換など、要素のストリームに対する関数型の操作をサポートするクラスです。
  • java.util.streamでのCollectorの使用

    Collectorを返すjava.util.streamのメソッド
    修飾子と型
    メソッド
    説明
    static <T> Collector<T,?,Double>
    Collectors.averagingDouble(ToDoubleFunction<? super T> mapper)
    入力要素にdouble値関数を適用した結果の算術平均を生成するCollectorを返します。
    static <T> Collector<T,?,Double>
    Collectors.averagingInt(ToIntFunction<? super T> mapper)
    入力要素にint値関数を適用した結果の算術平均を生成するCollectorを返します。
    static <T> Collector<T,?,Double>
    Collectors.averagingLong(ToLongFunction<? super T> mapper)
    入力要素にlong値関数を適用した結果の算術平均を生成するCollectorを返します。
    static <T, A, R, RR>
    Collector<T,A,RR>
    Collectors.collectingAndThen(Collector<T,A,R> downstream, Function<R,RR> finisher)
    追加の仕上げ変換が実行されるようにCollectorを適応させます。
    static <T> Collector<T,?,Long>
    Collectors.counting()
    T型の要素を受け入れて、入力要素の数をカウントする、Collectorを返します。
    static <T, A, R> Collector<T,?,R>
    Collectors.filtering(Predicate<? super T> predicate, Collector<? super T,A,R> downstream)
    述語を各入力要素に適用し、述語がtrueを返す場合にのみ累積することによって、Collectorを同じ型の要素Tを受け入れる要素に適合させます。
    static <T, U, A, R>
    Collector<T,?,R>
    Collectors.flatMapping(Function<? super T,? extends Stream<? extends U>> mapper, Collector<? super U,A,R> downstream)
    蓄積前に各入力要素にフラット・マッピング関数を適用することにより、型Uの要素を受け入れるCollectorを型Tの受け入れ要素に受け入れます。
    static <T, K> Collector<T,?,Map<K,List<T>>>
    Collectors.groupingBy(Function<? super T,? extends K> classifier)
    分類関数に従って要素をグループ化し、結果をMapに格納して返す、T型の入力要素に対する「グループ化」操作を実装したCollectorを返します。
    static <T, K, D, A, M extends Map<K, D>>
    Collector<T,?,M>
    Collectors.groupingBy(Function<? super T,? extends K> classifier, Supplier<M> mapFactory, Collector<? super T,A,D> downstream)
    分類関数に従って要素をグループ化した後、指定された下流Collectorを使って特定のキーに関連付けられた値のリダクション操作を実行する、T型の入力要素に対するカスケード「グループ化」操作を実装したCollectorを返します。
    static <T, K, A, D>
    Collector<T,?,Map<K,D>>
    Collectors.groupingBy(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)
    分類関数に従って要素をグループ化した後、指定された下流Collectorを使って特定のキーに関連付けられた値のリダクション操作を実行する、T型の入力要素に対するカスケード「グループ化」操作を実装したCollectorを返します。
    static <T, K> Collector<T,?,ConcurrentMap<K,List<T>>>
    Collectors.groupingByConcurrent(Function<? super T,? extends K> classifier)
    分類関数に従って要素をグループ化する、T型の入力要素に対する「グループ化」操作を実装した並行Collectorを返します。
    static <T, K, A, D, M extends ConcurrentMap<K, D>>
    Collector<T,?,M>
    Collectors.groupingByConcurrent(Function<? super T,? extends K> classifier, Supplier<M> mapFactory, Collector<? super T,A,D> downstream)
    分類関数に従って要素をグループ化した後、指定された下流Collectorを使って特定のキーに関連付けられた値のリダクション操作を実行する、T型の入力要素に対するカスケード「グループ化」操作を実装した並行Collectorを返します。
    static <T, K, A, D>
    Collector<T,?,ConcurrentMap<K,D>>
    Collectors.groupingByConcurrent(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)
    分類関数に従って要素をグループ化した後、指定された下流Collectorを使って特定のキーに関連付けられた値のリダクション操作を実行する、T型の入力要素に対するカスケード「グループ化」操作を実装した並行Collectorを返します。
    Collectors.joining()
    入力要素を検出順に連結して1つのStringにするCollectorを返します。
    Collectors.joining(CharSequence delimiter)
    入力要素を検出順に指定された区切り文字で区切りながら連結するCollectorを返します。
    Collectors.joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
    入力要素を検出順に指定された区切り文字で区切りながら連結し、指定された接頭辞と接尾辞を付加するCollectorを返します。
    static <T, U, A, R>
    Collector<T,?,R>
    Collectors.mapping(Function<? super T,? extends U> mapper, Collector<? super U,A,R> downstream)
    U型の要素を受け取るCollectorT型の要素を受け取れるように適応させるため、各入力要素にマッピング関数を適用した後で蓄積を行うようにします。
    static <T> Collector<T,?,Optional<T>>
    Collectors.maxBy(Comparator<? super T> comparator)
    指定されたComparatorに従ってOptional<T>として記述された最大要素を生成するCollectorを返します。
    static <T> Collector<T,?,Optional<T>>
    Collectors.minBy(Comparator<? super T> comparator)
    指定されたComparatorに従ってOptional<T>として記述された最小要素を生成するCollectorを返します。
    static <T, A, R> Collector<T,A,R>
    Collector.of(Supplier<A> supplier, BiConsumer<A,T> accumulator, BinaryOperator<A> combiner, Function<A,R> finisher, Collector.Characteristics... characteristics)
    指定されたsupplieraccumulatorcombiner、およびfinisher関数で記述される新しいCollectorを返します。
    static <T, R> Collector<T,R,R>
    Collector.of(Supplier<R> supplier, BiConsumer<R,T> accumulator, BinaryOperator<R> combiner, Collector.Characteristics... characteristics)
    指定されたsupplieraccumulator、およびcombiner関数で記述される新しいCollectorを返します。
    static <T> Collector<T,?,Map<Boolean,List<T>>>
    Collectors.partitioningBy(Predicate<? super T> predicate)
    Predicateに従って入力要素を分割し、結果をMap<Boolean, List<T>>内に格納するCollectorを返します。
    static <T, D, A> Collector<T,?,Map<Boolean,D>>
    Collectors.partitioningBy(Predicate<? super T> predicate, Collector<? super T,A,D> downstream)
    Predicateに従って入力要素を分割し、別のCollectorに従って各パーティションの値をリデュースし、結果をMap<Boolean, D>内に格納するCollectorを返します(下流のリダクションの結果がマップの値になる)。
    static <T> Collector<T,?,Optional<T>>
    Collectors.reducing(BinaryOperator<T> op)
    指定されたBinaryOperatorの下で入力要素のリダクションを実行するCollectorを返します。
    static <T> Collector<T,?,T>
    Collectors.reducing(T identity, BinaryOperator<T> op)
    指定されたBinaryOperatorの下で指定された単位元を使って入力要素のリダクションを実行するCollectorを返します。
    static <T, U> Collector<T,?,U>
    Collectors.reducing(U identity, Function<? super T,? extends U> mapper, BinaryOperator<U> op)
    指定されたマッピング関数とBinaryOperatorの下で入力要素のリダクションを実行するCollectorを返します。
    Collectors.summarizingDouble(ToDoubleFunction<? super T> mapper)
    各入力要素にdouble生成マッピング関数を適用し、その結果の値のサマリー統計を返すCollectorを返します。
    Collectors.summarizingInt(ToIntFunction<? super T> mapper)
    各入力要素にint生成マッピング関数を適用し、その結果の値のサマリー統計を返すCollectorを返します。
    Collectors.summarizingLong(ToLongFunction<? super T> mapper)
    各入力要素にlong生成マッピング関数を適用し、その結果の値のサマリー統計を返すCollectorを返します。
    static <T> Collector<T,?,Double>
    Collectors.summingDouble(ToDoubleFunction<? super T> mapper)
    入力要素に適用されたdouble値関数の合計を生成するCollectorを返します。
    static <T> Collector<T,?,Integer>
    Collectors.summingInt(ToIntFunction<? super T> mapper)
    入力要素に適用された整数値関数の合計を生成するCollectorを返します。
    static <T> Collector<T,?,Long>
    Collectors.summingLong(ToLongFunction<? super T> mapper)
    入力要素に適用されたlong値関数の合計を生成するCollectorを返します。
    static <T, R1, R2, R>
    Collector<T,?,R>
    Collectors.teeing(Collector<? super T,?,R1> downstream1, Collector<? super T,?,R2> downstream2, BiFunction<? super R1,? super R2,R> merger)
    2つのダウンストリーム・コレクタのコンポジットであるCollectorを返します。
    static <T, C extends Collection<T>>
    Collector<T,?,C>
    Collectors.toCollection(Supplier<C> collectionFactory)
    入力要素を検出順に新しいCollectionに蓄積するCollectorを返します。
    static <T, K, U> Collector<T,?,ConcurrentMap<K,U>>
    Collectors.toConcurrentMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)
    ConcurrentMap内に要素を累積する並行Collectorを返します(指定されたマッピング関数を入力要素に適用した結果が、マップのキーと値になる)。
    static <T, K, U> Collector<T,?,ConcurrentMap<K,U>>
    Collectors.toConcurrentMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction)
    ConcurrentMap内に要素を累積する並行Collectorを返します(指定されたマッピング関数を入力要素に適用した結果が、マップのキーと値になる)。
    static <T, K, U, M extends ConcurrentMap<K, U>>
    Collector<T,?,M>
    Collectors.toConcurrentMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction, Supplier<M> mapFactory)
    ConcurrentMap内に要素を累積する並行Collectorを返します(指定されたマッピング関数を入力要素に適用した結果が、マップのキーと値になる)。
    static <T> Collector<T,?,List<T>>
    Collectors.toList()
    入力要素を新しいListに蓄積するCollectorを返します。
    static <T, K, U> Collector<T,?,Map<K,U>>
    Collectors.toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)
    Map(そのキーと値は指定されたマッピング関数を入力要素に適用した結果である)内に要素を蓄積するCollectorを返します。
    static <T, K, U> Collector<T,?,Map<K,U>>
    Collectors.toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction)
    Map(そのキーと値は指定されたマッピング関数を入力要素に適用した結果である)内に要素を蓄積するCollectorを返します。
    static <T, K, U, M extends Map<K, U>>
    Collector<T,?,M>
    Collectors.toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction, Supplier<M> mapFactory)
    Map(そのキーと値は指定されたマッピング関数を入力要素に適用した結果である)内に要素を蓄積するCollectorを返します。
    static <T> Collector<T,?,Set<T>>
    Collectors.toSet()
    入力要素を新しいSetに蓄積するCollectorを返します。
    static <T> Collector<T,?,List<T>>
    Collectors.toUnmodifiableList()
    Collectorを返します。これは入力要素を「変更不可能なリスト」に遭遇順序で累積します。
    static <T, K, U> Collector<T,?,Map<K,U>>
    Collectors.toUnmodifiableMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)
    入力要素を「変更不可能なマップ」に蓄積するCollectorを返します。そのキーと値は、提供されたマッピング関数を入力要素に適用した結果です。
    static <T, K, U> Collector<T,?,Map<K,U>>
    Collectors.toUnmodifiableMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction)
    入力要素を「変更不可能なマップ」に蓄積するCollectorを返します。そのキーと値は、提供されたマッピング関数を入力要素に適用した結果です。
    static <T> Collector<T,?,Set<T>>
    Collectors.toUnmodifiableSet()
    入力要素を「変更不可能なセット」に蓄積するCollectorを返します。
    Collector型のパラメータを持つjava.util.streamのメソッド
    修飾子と型
    メソッド
    説明
    <R, A> R
    Stream.collect(Collector<? super T,A,R> collector)
    Collectorを使ってこのストリームの要素に対する可変リダクション操作を実行します。
    static <T, A, R, RR>
    Collector<T,A,RR>
    Collectors.collectingAndThen(Collector<T,A,R> downstream, Function<R,RR> finisher)
    追加の仕上げ変換が実行されるようにCollectorを適応させます。
    static <T, A, R> Collector<T,?,R>
    Collectors.filtering(Predicate<? super T> predicate, Collector<? super T,A,R> downstream)
    述語を各入力要素に適用し、述語がtrueを返す場合にのみ累積することによって、Collectorを同じ型の要素Tを受け入れる要素に適合させます。
    static <T, U, A, R>
    Collector<T,?,R>
    Collectors.flatMapping(Function<? super T,? extends Stream<? extends U>> mapper, Collector<? super U,A,R> downstream)
    蓄積前に各入力要素にフラット・マッピング関数を適用することにより、型Uの要素を受け入れるCollectorを型Tの受け入れ要素に受け入れます。
    static <T, K, D, A, M extends Map<K, D>>
    Collector<T,?,M>
    Collectors.groupingBy(Function<? super T,? extends K> classifier, Supplier<M> mapFactory, Collector<? super T,A,D> downstream)
    分類関数に従って要素をグループ化した後、指定された下流Collectorを使って特定のキーに関連付けられた値のリダクション操作を実行する、T型の入力要素に対するカスケード「グループ化」操作を実装したCollectorを返します。
    static <T, K, A, D>
    Collector<T,?,Map<K,D>>
    Collectors.groupingBy(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)
    分類関数に従って要素をグループ化した後、指定された下流Collectorを使って特定のキーに関連付けられた値のリダクション操作を実行する、T型の入力要素に対するカスケード「グループ化」操作を実装したCollectorを返します。
    static <T, K, A, D, M extends ConcurrentMap<K, D>>
    Collector<T,?,M>
    Collectors.groupingByConcurrent(Function<? super T,? extends K> classifier, Supplier<M> mapFactory, Collector<? super T,A,D> downstream)
    分類関数に従って要素をグループ化した後、指定された下流Collectorを使って特定のキーに関連付けられた値のリダクション操作を実行する、T型の入力要素に対するカスケード「グループ化」操作を実装した並行Collectorを返します。
    static <T, K, A, D>
    Collector<T,?,ConcurrentMap<K,D>>
    Collectors.groupingByConcurrent(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)
    分類関数に従って要素をグループ化した後、指定された下流Collectorを使って特定のキーに関連付けられた値のリダクション操作を実行する、T型の入力要素に対するカスケード「グループ化」操作を実装した並行Collectorを返します。
    static <T, U, A, R>
    Collector<T,?,R>
    Collectors.mapping(Function<? super T,? extends U> mapper, Collector<? super U,A,R> downstream)
    U型の要素を受け取るCollectorT型の要素を受け取れるように適応させるため、各入力要素にマッピング関数を適用した後で蓄積を行うようにします。
    static <T, D, A> Collector<T,?,Map<Boolean,D>>
    Collectors.partitioningBy(Predicate<? super T> predicate, Collector<? super T,A,D> downstream)
    Predicateに従って入力要素を分割し、別のCollectorに従って各パーティションの値をリデュースし、結果をMap<Boolean, D>内に格納するCollectorを返します(下流のリダクションの結果がマップの値になる)。
    static <T, R1, R2, R>
    Collector<T,?,R>
    Collectors.teeing(Collector<? super T,?,R1> downstream1, Collector<? super T,?,R2> downstream2, BiFunction<? super R1,? super R2,R> merger)
    2つのダウンストリーム・コレクタのコンポジットであるCollectorを返します。