インタフェース
java.util.stream.Collectorの使用
パッケージ | 説明 |
---|---|
java.util.stream |
コレクションに対するマップ-リデュース変換など、要素のストリームに対する関数型の操作をサポートするクラスです。
|
-
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
を返します。static Collector<CharSequence,?,String>
Collectors. joining()
入力要素を検出順に連結して1つのString
にするCollector
を返します。static Collector<CharSequence,?,String>
Collectors. joining(CharSequence delimiter)
入力要素を検出順に指定された区切り文字で区切りながら連結するCollector
を返します。static Collector<CharSequence,?,String>
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
型の要素を受け取るCollector
がT
型の要素を受け取れるように適応させるため、各入力要素にマッピング関数を適用した後で蓄積を行うようにします。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)
指定されたsupplier
、accumulator
、combiner
、およびfinisher
関数で記述される新しいCollector
を返します。static <T, R> Collector<T,R,R>
Collector. of(Supplier<R> supplier, BiConsumer<R,T> accumulator, BinaryOperator<R> combiner, Collector.Characteristics... characteristics)
指定されたsupplier
、accumulator
、および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
を返します。static <T> Collector<T,?,DoubleSummaryStatistics>
Collectors. summarizingDouble(ToDoubleFunction<? super T> mapper)
各入力要素にdouble
生成マッピング関数を適用し、その結果の値のサマリー統計を返すCollector
を返します。static <T> Collector<T,?,IntSummaryStatistics>
Collectors. summarizingInt(ToIntFunction<? super T> mapper)
各入力要素にint
生成マッピング関数を適用し、その結果の値のサマリー統計を返すCollector
を返します。static <T> Collector<T,?,LongSummaryStatistics>
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
型の要素を受け取るCollector
がT
型の要素を受け取れるように適応させるため、各入力要素にマッピング関数を適用した後で蓄積を行うようにします。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
を返します。