Observable<Object> observableOne = Observable.just("java", "spring", "hibernate", 1, 2, 3);
Observable<Integer> observableFinal = observableOne.ofType(Integer.class);
// OR
// Observable<String> observableFinal = observableOne.ofType(String.class); //
observableFinal.subscribe(s -> {
System.out.print(s);
});
----------------------------------------------------------------------------
Observable<String> observableOne = Observable.just("java", "spring", "hibernate", "android", "rxjava");
ObservableSource<String> observableTwo = Observable.just("c", "c plus", "perl", "c sharp", "dot net");
Observable<String> observableFinal = observableOne.mergeWith(observableTwo);
observableFinal.subscribe(s -> {
System.out.print(s);
});
-------------------------------------------------------------------------------
Observable<String> observable = Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> e) throws Exception {
String s = null;
e.onNext("STRUTS");
e.onNext("SPRING");
e.onNext("TILES");
e.onNext("JSTL");
e.onComplete();
}
});
ConnectableObservable<String> publishObservable = observable.publish();
publishObservable.subscribe(s -> { System.out.println("subscriber one "+s);});
publishObservable.subscribe(s -> { System.out.println("subscriber two "+s);});
publishObservable.connect();
publishObservable.subscribe(s -> { System.out.println("subscriber three "+s);});
--------------------------------------------------------------------------------------
Observable<Integer> observable = Observable.range(1, 10);
Maybe<Integer> maybeObservable = observable.reduce(new BiFunction<Integer, Integer, Integer>(){
@Override
public Integer apply(Integer t, Integer st) throws Exception {
return t + st;
}
});
maybeObservable.subscribe(s -> { System.out.println("reduce value "+s);});
22
No comments:
Post a Comment