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
2 Answers
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));