The Observable.just method

The just() method emits its parameter(s) as OnNext notifications, and after that, it emits an OnCompleted notification.

For example, one letter:

Observable.just('S').subscribe(System.out::println);

Or a sequence of letters:

Observable
  .just('R', 'x', 'J', 'a', 'v', 'a')
  .subscribe(
    System.out::print,
    System.err::println,
    System.out::println
  );

The first piece of code prints S and a new line, and the second prints the letters on a single line and adds a new line on completion. The method allows up to nine arbitrary values (objects of the same type) to be observed through reactive means. For example, say we have this simple User class:

public static class User { private final String forename; private final String lastname; public ...

Get Learning Reactive Programming with Java 8 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.