content: package com.rxjava2.android.samples.ui.operators;
  
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  
  import com.rxjava2.android.samples.R;
  import com.rxjava2.android.samples.utils.AppConstant;
  
  import androidx.annotation.Nullable;
  import androidx.appcompat.app.AppCompatActivity;
  import io.reactivex.Observable;
  import io.reactivex.Observer;
  import io.reactivex.disposables.Disposable;
  
  /**
   * Created by techteam on 13/09/16.
   */
  public class DistinctExampleActivity extends AppCompatActivity {
  
      private static final String TAG = DistinctExampleActivity.class.getSimpleName();
      Button btn;
      TextView textView;
  
      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_example);
          btn = findViewById(R.id.btn);
          textView = findViewById(R.id.textView);
  
          btn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  doSomeWork();
              }
          });
      }
  
      /*
       * distinct() suppresses duplicate items emitted by the source Observable.
       */
      private void doSomeWork() {
  
          getObservable()
                  .distinct()
                  .subscribe(getObserver());
      }
  
      private Observable<Integer> getObservable() {
          return Observable.just(1, 2, 1, 1, 2, 3, 4, 6, 4);
      }
  
  
      private Observer<Integer> getObserver() {
          return new Observer<Integer>() {
  
              @Override
              public void onSubscribe(Disposable d) {
                  Log.d(TAG, " onSubscribe : " + d.isDisposed());
              }
  
              @Override
              public void onNext(Integer value) {
                  textView.append(" onNext : value : " + value);
                  textView.append(AppConstant.LINE_SEPARATOR);
                  Log.d(TAG, " onNext value : " + value);
              }
  
              @Override
              public void onError(Throwable e) {
                  Log.d(TAG, " onError : " + e.getMessage());
              }
  
              @Override
              public void onComplete() {
                  Log.d(TAG, " onComplete");
              }
          };
      }
  }