0

Im trying to do the following: 1. Get Observables from ArrayList 2. Get name field from each item of this list 3. Create new ArrayList

 @NonNull
@Override
public Observable<Response<FriendsCheckResponse>> getFriendsInApp(String query) {
    List<String> test = new ArrayList<>();
    Observable.from(getContactList())
            .map(contactItem -> {
                test.add(contactItem.getNumber());
                return null;
            })
            .subscribeOn(Schedulers.immediate())
            .observeOn(AndroidSchedulers.mainThread());

}
1
  • Why do you need an Observable for this? You can just do this with the stream-API: getContactList().stream().map(contactItem -> contactItem.getNumber()).collect(Collectors.toList());. Commented Sep 27, 2016 at 13:14

1 Answer 1

1

Use toList to collect them into one List. There is no need for subscribeOn and observeOn in this case (plus subscribeOn(immediate()) is functionally a no-op.

Observable<List<String>> numbers = Observable.from(getContactList())
    .map(v -> v.getNumber())
    .toList();
Sign up to request clarification or add additional context in comments.

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.