...

/

Creating an Observable

Creating an Observable

Learn the various ways of creating an Observable.

Different ways to create an Observable

Now that we have a basic, high-level understanding of the different components of RxJava, let’s dive into the Observable a bit more, specifically, different ways that we can create one. We’ve glanced at the most verbose way of creating an Observable ( .create()). However, there are simpler and more convenient APIs that are available to us.

.just()

The Observable.just(T item) method is one of the most common ways to wrap any object to an Observable. It creates an Observable of type T that just emits the provided item via an Observer's .onNext() method and then completes via .onComplete(). The Observable.just() is also overloaded, and we can specify anywhere from one to nine items ...