0

I have an arraylist which contains a set of objects.I would like to use rxjava so i can loop through the list in such a way that in the onSubscribe method instead of getting the entire list at once i get each list item 1 at a time

1
  • 2
    That's almost at the top of every RXJava example… try a search engine for once! :) Commented Mar 3, 2017 at 19:10

2 Answers 2

5

It was actually Observable.fromIterable that did the trick, Observable.from returns the entire array at a time.

Sign up to request clarification or add additional context in comments.

Comments

0

If you are on android it is recommended to use retrolambda and rxandroid too. You can remove filter ofc. This line: .subscribeOn(Schedulers.newThread()) is for android only too.

List<Integer> array = new ArrayList<>();

array.add(0);
array.add(1);
array.add(2);
array.add(5);
array.add(10);

Observable.fromIterable(array)
    .subscribeOn(Schedulers.newThread())
    .filter(integer -> integer % 2 == 0)
    .subscribe(integer -> Log.e(TAG, "" + integer));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.