After covering merging and concatenation, let's get an easy combining operation out of the way. The Observable.amb() factory (amb stands for ambiguous) accepts an Iterable<Observable<T>> object as a parameter and emits the values of the first Observable that emits, while the others are disposed of. This is helpful when there are multiple sources of the same data or events and you want the fastest one to win.
Here, we have two interval sources and we combine them with the Observable.amb() factory. If one emits every second while the other emits every 300 milliseconds, the latter is going to win because it emits more often:
import io.reactivex.rxjava3.core.Observable;
public class Ch4_12 {
public static void main(String[] args) {
//emit every second
Observable<String> src1 =
Observable.interval(1, TimeUnit.SECONDS...