DefaultIfEmpty
emit items from the source Observable, or a default item if the source Observable emits nothing
The DefaultIfEmpty operator simply mirrors the source Observable exactly if the source Observable emits any items. If the source Observable terminates normally (with an
onComplete
) without emitting any items, the Observable returned from DefaultIfEmpty will instead emit a default item of your choosing before it too completes.
----------------------------------------------------
Observable.empty()
.defaultIfEmpty(0)
.subscribe(v -> System.out.println(v));
---------------------------------------------------
22
No comments:
Post a Comment