Search code examples
javarx-javareactive-programming

Convert observable to list


I am using RxJava.

I have an Observable<T>. How do I convert it to List<T>?

Seems to be a simple operation, but I couldn't find it anywhere on the net.


Solution

  • You can use toList() or toSortedList() . For e.g.

    observable.toList(myObservable)
              .subscribe({ myListOfSomething -> do something useful with the list });