Search code examples
javaobservablerx-javablockingbuilder

Java / Converting from Observable<List<String>> to List<String>


I have a result set from SQL Query

Builder object_key = db.select(String.format("select object_key from "
+ CAMPAIGN_TABLE));

that returns a Builder data type. I need to store the output of the SQL Query in List<String> object_key_list. I am not sure how to do that. Can anyone be able to help me with it?

  1. If I call

    object_key.autoMap(String.class);

then that returns an Observable<String> data type.

  1. If I call

    object_key.autoMap(String.class).toList();

then that returns an Observable<List<String>> data type.

  1. If I call

    object_key.autoMap(String.class).toList().toBlocking();

then that returns an BlockingObservable<List<String>> data type.

  1. If I call

    object_key.autoMap(String.class).toList().toSingle();

then that returns an Single<List<String>> data type.

How is it possible to get a List<String> value for object_key_list as a returned data type?

By the way, what is that confusing enough Observable as a returned data type first of all?


Solution

  • You need to subscribe to your observable, e.g.:

    Observable<List<String>> o = Observable.empty();
    // ....
    o.subscribe(strings -> {
      // strings is list you are looking for
    });
    

    After you subscribe, whenever you get result from your db, you would be notified and you can do something with your list of string. I hope it would help.