I was checking the documentation of RXJava and I notice that concat and merge operators seems do the same. I wrote a couple test to be sure.
@Test
public void testContact() {
Observable.concat(Observable.just("Hello"),
Observable.just("reactive"),
Observable.just("world"))
.subscribe(System.out::println);
}
@Test
public void testMerge() {
Observable.merge(Observable.just("Hello"),
Observable.just("reactive"),
Observable.just("world"))
.subscribe(System.out::println);
}
The documentation says
The Merge operator is also similar. It combines the emissions of two or more Observables, but may interleave them, whereas Concat never interleaves the emissions from multiple Observables.
But still I don't full understand, running this test thousand of times the merge result always is the same. Since the order is not granted I was expecting sometimes "reactive" "world" "hello" for example.
The code is here https://github.com/politrons/reactive
See Question&Answers more detail:os