The Observable.from method
The Observable.from
method can create an Observable
instance from different Java structures. For example:
List<String> list = Arrays.asList( "blue", "red", "green", "yellow", "orange", "cyan", "purple" ); Observable<String> listObservable = Observable.from(list); listObservable.subscribe(System.out::println);
This piece of code creates an Observable
instance from a List
instance. When the subscribe
method is called on the Observable
instance, all of the elements contained in the source list are emitted to the subscribing method. For every call to the subscribe()
method, the whole collection is emitted from the beginning, element by element:
listObservable.subscribe( color -> System.out.print(color + "|"), System.out::println, System.out::println ); listObservable.subscribe(color -> System.out.print(color + "/"));
This will print the colors twice with...