What is the difference between concatMap and flatMap in RxJava

As you wrote, the two functions are very similar and the subtle difference is how the output is created ( after the mapping function is applied).

Flat map uses merge operator while concatMap uses concat operator.

As you see the concatMap output sequence is ordered – all of the items emitted by the first Observable being emitted before any of the items emitted by the second Observable,
while flatMap output sequence is merged – the items emitted by the merged Observable may appear in any order, regardless of which source Observable they came from.

Leave a Comment