src/main/java/io/reactivex/Flowable.java
@CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <U> Single<U> collect(Callable<? extends U> initialItemSupplier, BiConsumer<? super U, ? super T> collector) {
        ObjectHelper.requireNonNull(initialItemSupplier, "initialItemSupplier is null");
        ObjectHelper.requireNonNull(collector, "collector is null");
        return RxJavaPlugins.onAssembly(new FlowableCollectSingle<T, U>(this, initialItemSupplier, collector));
    }
@CheckReturnValue
    @NonNull
    @BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
    @SchedulerSupport(SchedulerSupport.NONE)
    public final <U> Single<U> collect(Callable<? extends U> initialItemSupplier, BiConsumer<? super U, ? super T> collector) {
        ObjectHelper.requireNonNull(initialItemSupplier, "initialItemSupplier is null");
        ObjectHelper.requireNonNull(collector, "collector is null");
        return RxJavaPlugins.onAssembly(new FlowableCollectSingle<T, U>(this, initialItemSupplier, collector));
    }
@ CheckReturnValue @ NonNull @ BackpressureSupport ( BackpressureKind . UNBOUNDED_IN ) @ SchedulerSupport ( SchedulerSupport . NONE ) public final < U > Single < U > collect ( Callable < ? extends U > initialItemSupplier , BiConsumer < ? super U , ? super T > collector ) { ObjectHelper . requireNonNull ( initialItemSupplier , "initialItemSupplier is null" ) ; ObjectHelper . requireNonNull ( collector , "collector is null" ) ; return RxJavaPlugins . onAssembly ( new FlowableCollectSingle < T , U > ( this , initialItemSupplier , collector ) ) ; }
Collects items emitted by the finite source Publisher into a single mutable data structure and returns
a Single that emits this structure.
<p>
<img width="640" height="330" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/collect.png" alt="">
<p>
This is a simplified version of {@code reduce} that does not need to return the state on each pass.
<p>
Note that this operator requires the upstream to signal {@code onComplete} for the accumulator object to
be emitted. Sources that are infinite and never complete will never emit anything through this
operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
<dl>
<dt><b>Backpressure:</b></dt>
<dd>This operator does not support backpressure because by intent it will receive all values and reduce
them to a single {@code onNext}.</dd>
<dt><b>Scheduler:</b></dt>
<dd>{@code collect} does not operate by default on a particular {@link Scheduler}.</dd>
</dl>

@param <U> the accumulator and output type
@param initialItemSupplier
the mutable data structure that will collect the items
@param collector
a function that accepts the {@code state} and an emitted item, and modifies {@code state}
accordingly
@return a Single that emits the result of collecting the values emitted by the source Publisher
into a single mutable data structure
@see <a href="http://reactivex.io/documentation/operators/reduce.html">ReactiveX operators documentation: Reduce</a>
Collects items emitted by the finite source Publisher into a single mutable data structure and returns a Single that emits this structure . <p > <img width = 640 height = 330 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / collect . png alt = > <p > This is a simplified version of { @code reduce } that does not need to return the state on each pass . <p > Note that this operator requires the upstream to signal { @code onComplete } for the accumulator object to be emitted . Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatal { @code OutOfMemoryError } . <dl > <dt > <b > Backpressure : < / b > < / dt > <dd > This operator does not support backpressure because by intent it will receive all values and reduce them to a single { @code onNext } . < / dd > <dt > <b > Scheduler : < / b > < / dt > <dd > { @code collect } does not operate by default on a particular { @link Scheduler } . < / dd > < / dl >