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 java.util.List;
  
  import androidx.appcompat.app.AppCompatActivity;
  import io.reactivex.Observable;
  import io.reactivex.Observer;
  import io.reactivex.disposables.Disposable;
  
  /**
   * Created by amitshekhar on 27/08/16.
   */
  public class BufferExampleActivity extends AppCompatActivity {
  
      private static final String TAG = BufferExampleActivity.class.getSimpleName();
      Button btn;
      TextView textView;
  
      @Override
      protected void onCreate(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();
              }
          });
      }
  
      /*
       * simple example using buffer operator - bundles all emitted values into a list
       */
      private void doSomeWork() {
  
          Observable<List<String>> buffered = getObservable().buffer(3, 1);
  
          // 3 means,  it takes max of three from its start index and create list
          // 1 means, it jumps one step every time
          // so the it gives the following list
          // 1 - one, two, three
          // 2 - two, three, four
          // 3 - three, four, five
          // 4 - four, five
          // 5 - five
  
          buffered.subscribe(getObserver());
      }
  
      private Observable<String> getObservable() {
          return Observable.just("one", "two", "three", "four", "five");
      }
  
      private Observer<List<String>> getObserver() {
          return new Observer<List<String>>() {
  
              @Override
              public void onSubscribe(Disposable d) {
                  Log.d(TAG, " onSubscribe : " + d.isDisposed());
              }
  
              @Override
              public void onNext(List<String> stringList) {
                  textView.append(" onNext size : " + stringList.size());
                  textView.append(AppConstant.LINE_SEPARATOR);
                  Log.d(TAG, " onNext : size :" + stringList.size());
                  for (String value : stringList) {
                      textView.append(" value : " + value);
                      textView.append(AppConstant.LINE_SEPARATOR);
                      Log.d(TAG, " : value :" + value);
                  }
  
              }
  
              @Override
              public void onError(Throwable e) {
                  textView.append(" onError : " + e.getMessage());
                  textView.append(AppConstant.LINE_SEPARATOR);
                  Log.d(TAG, " onError : " + e.getMessage());
              }
  
              @Override
              public void onComplete() {
                  textView.append(" onComplete");
                  textView.append(AppConstant.LINE_SEPARATOR);
                  Log.d(TAG, " onComplete");
              }
          };
      }
  
  
  }