RxJava - Single Observable

Single is an observable that emits only a single item. The factory operators for Single is more or less similar with observables restricted to a single emission. The only noticeable difference is the observer definition

public interface SingleObserver<T> {

    void onSubscribe(@NonNull Disposable d);

    void onSuccess(@NonNull T t);

    void onError(@NonNull Throwable e);


Like Observable there are no more onNext() and onComplete().


Single so=Single.create(new SingleOnSubscribe<String>() {

            public void subscribe(SingleEmitter<String> se) throws Exception {
                se.onSuccess("Success ");
                //se.onError(new Throwable("Exception"));


While compile and run this will retrun the result as


if we need to perform a one time network request, we can create it using Single and users of this observable does not need to look at the implementation details to know what to expect from this observable

Example 2:

  Single<String> testSingle = Single.just("Single Observable");

      //Create an observer
      Disposable disposable = testSingle
         .delay(2, TimeUnit.SECONDS, Schedulers.io())
         new DisposableSingleObserver<String>() {

         public void onError(Throwable e) { 

         public void onSuccess(String value) {
      //start observing


This will return output after 2 seconds

Single Observable