How to create an observable from a hashmap?

Based on ReactiveX Documentation

the from statement can transform Future, Iterable, or Array. In the case of Iterable or Array, the resulting Observable will emit every element contained in Iterable or Array.

we can observe observables from Array or List , and observables emit elements in the list.

I have a HashMap<String,Item> , and I want to iterate over the elements in the same way as doing observables using Observable.from(List<Item>) .

In other words, I want the observable to emit HashMap Items .

Is there a solution for this?

+4
source share
1 answer

You can make map entries in Observed as follows:

 Observable<Entry<String, Item>> entries = Observable.from(map.entrySet()); 

If you just need the values ​​from the map:

 Observable<Item> items = Observable.from(map.values()); 
+14
source

All Articles