//Print Method - 1
Observable.just("Hello RxJava").subscribe(line -> System.out.println(line));
//Print Method - 2
Observable.just("Hello RxJava").subscribe(System.out::println);
Print Different Data Type
// String
Observable.just("Hello RxJava").subscribe(System.out::println);
// Int
Observable.just(55).subscribe(System.out::println);
// Double
Observable.just(49.63).subscribe(System.out::println);
// Char
Observable.just('A').subscribe(System.out::println);
// Boolean
Observable.just(false).subscribe(System.out::println);
// Array
Observable.just("one", "two", "three").subscribe(System.out::println);
// List
List<String> list = new ArrayList<>();
list.add("List-1");
list.add("List-2");
list.add("List-3");
list.add("List-4");
Observable.just(list).subscribe(System.out::println);
1. fromArray() method
--------------------------------------------------
String[] count = {"1", "2", "3", "4" };
Observable.fromArray(count).subscribe(value -> {
System.out.println(value);
});
--------------------------------------------------
Calling Observable by method
------------------------------------------------------
import io.reactivex.Observable;
public class HomeClass {
public static void main(String[] args){
fakeUserInput().subscribe(System.out::println);
}
public static Observable<Integer> fakeUserInput(){
return Observable.just(10, 17, 3, 8);
}
}
22
No comments:
Post a Comment